8
Reply

How to call and use stored procedure in codebehind page?

poornima sekar

poornima sekar

Nov 2 2016 3:32 AM
241
Hi,
I need to call stored procedure and use that values in codebehind page.
Below is my coding,
public Room1 GetRoomById(int Id)
{
string cs = ConfigurationManager.ConnectionStrings["LinqChatConnectionString"].ConnectionString;
DataSet dt = new DataSet();
try
{
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("GetRoomById", con);
cmd.Parameters.AddWithValue("@RoomID", Convert.ToInt32(lblRoomId.Text));
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
Room1 room = new Room1();
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (dt)
{
sda.Fill(dt);
 room=dt; //Getting Error. Here I don't know how to assign the retrieved values to the object.
}
}
}
}
catch(Exception ex)
{ }
 
Please help me to overcome this issue.
Thanks,
Poornima
 
 
 

Answers (8)