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)
{ }
}
{
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
Salman BegPosted Nov 2, 2016, 5:47 AM
poornima sekarPosted Nov 2, 2016, 9:55 PM
Bikesh SrivastavaPosted Nov 2, 2016, 7:06 AM
poornima sekarPosted Nov 2, 2016, 6:22 AM
poornima sekarPosted Nov 2, 2016, 5:40 AM
{
string cs = ConfigurationManager.ConnectionStrings["LinqChatConnectionString"].ConnectionString;
DataSet dt = new DataSet();
try
{
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("GetRoomById", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
cmd.Parameters.AddWithValue("@RoomID",rId);
SqlDataReader rdr = cmd.ExecuteReader();//->Throwing exception here
if (rdr.HasRows)
{
while (rdr.Read())
{
lblRoomId.Text = rdr["RoomID"].ToString();
lblRoomName.Text = rdr["Name"].ToString();
}
}
con.Close();
}
}
catch(Exception ex)
{ }
}
Nitin SontakkePosted Nov 2, 2016, 4:55 AM
Ananth GPosted Nov 2, 2016, 4:30 AM
Salman BegPosted Nov 2, 2016, 4:17 AM