public void getAllMotel(string userID) { con = DBServices.openConnection(); command.Connection = con; command.CommandText = "SELECT ID,NAME,Address,Information,Longitude,Latitude FROM Motel WHERE UserID=@userID "; command.Parameters.Add("@userID", SqlDbType.NVarChar, 50).Value = userID; dr = command.ExecuteReader(); while (dr.Read()) { if (MotelList == null) { MotelList = new List <MotelDTO>(); } MotelDTO tmp = new MotelDTO(); tmp.MotelID = dr.GetString(0); tmp.MotelName = dr.GetString(1); tmp.MotelAddress = dr.GetString(2); tmp.Information = dr.GetString(3); tmp.Longitude = dr.GetString(4); tmp.Latitude = dr.GetString(5); MotelList.Add(tmp); } }
public string InsertMotel(MotelDTO dto) { con = DBServices.openConnection(); command.Connection = con; command.CommandText = "INSERT INTO Motel(ID,Name,UserID,Address,Information,Longitude,Latitude) " + "VALUES (@Id,@Name,@UserID,@Address,@Inforation,@Longitude,@Latitude)"; command.Parameters.Add("@Id", SqlDbType.VarChar, 10).Value = dto.MotelID; command.Parameters.Add("@Name", SqlDbType.NVarChar, 50).Value = dto.MotelName; command.Parameters.Add("@UserID", SqlDbType.NVarChar, 50).Value = dto.OnwerID; command.Parameters.Add("@Address", SqlDbType.NVarChar, 200).Value = dto.MotelAddress; command.Parameters.Add("@Inforation", SqlDbType.NVarChar, 500).Value = dto.Information + ""; command.Parameters.Add("@Longitude", SqlDbType.NVarChar, 500).Value = dto.Longitude; command.Parameters.Add("@Latitude", SqlDbType.NVarChar, 500).Value = dto.Latitude; int rs = command.ExecuteNonQuery(); if (rs > 0) { con.Close(); return("success"); } con.Close(); return("fail"); }