有人可以帮我调试我的代码吗?
基本上,我已经创建了一个存储过程,我想在我的网站(ASP.NET)中调用该存储过程。
此代码适用于我的存储过程:
CREATE PROCEDURE usp_hotelRoom
@country VARCHAR(50),
@name VARCHAR(50)
AS
BEGIN
SELECT
Room.roomID, Room.roomName, Room.type, Room.capacity, Room.roomSize,
Room.description, Room.remarks, Room.services, Room.photo,
Room.price, Hotel.name
FROM
Room
INNER JOIN
Hotel ON Hotel.orgEmail = Room.orgEmail
WHERE
country = @country
AND Hotel.name = @name;
END
EXEC usp_hotelRoom 'singapore', 'marina bay sands';
此代码用于调用存储过程:
public static List<Room> getHotelRoomByCountry(string country, string name)
{
SqlConnection con = new SqlConnection(conStr);
try
{
SqlCommand command = new SqlCommand();
command.Connection = con;
command.CommandType = System.Data.CommandType.StoredProcedure;
command.CommandText = "usp_hotelRoom";
var paramname = new SqlParameter
{
ParameterName = "@country",
Value = country
};
command.Parameters.Add(paramname);
var paramhotel = new SqlParameter
{
ParameterName = "@hotel.name",
Value = name
};
command.Parameters.Add(paramhotel);
con.Open();
SqlDataReader reader = command.ExecuteReader();
List<Room> rooms = null;
if (reader.HasRows)
rooms = new List<Room>();
while (reader.Read())
{
rooms.Add(
new Room()
{
RoomID = reader["roomID"].ToString(),
RoomName = reader["roomName"].ToString(),
Type = reader["type"].ToString(),
Capacity = reader["capacity"].ToString(),
RoomSize = reader["roomSize"].ToString(),
Desc = reader["description"].ToString(),
Remarks = reader["remarks"].ToString(),
Services = reader["services"].ToString(),
Pictures = reader["photo"].ToString(),
Price = reader["price"].ToString(),
});
}
reader.Close();
return rooms;
}
finally
{
con.Close();
}
}
希望有人可以帮助我。在您的工作中,我将不胜感激!
我尝试自己做,但直到我尝试在Room类(Hotel.Name
)内添加新的类属性之前,都无法使用
谢谢!
答案 0 :(得分:4)
更改此代码行
ParameterName = "@hotel.name"
到
ParameterName = "@name"