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 BegRank #284 · 8.8K reputationPosted Nov 2, 2016, 1:47 AM EDT
poornima sekar26 reputationPosted Nov 2, 2016, 1:40 AM EDT
{
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)
{ }
}
Salman BegRank #284 · 8.8K reputationPosted Nov 2, 2016, 12:17 AM EDT
Ananth GRank #1,176 · 1.5K reputationPosted Nov 2, 2016, 12:30 AM EDT
Nitin SontakkeRank #264 · 9.6K reputationPosted Nov 2, 2016, 12:55 AM EDT
poornima sekar26 reputationPosted Nov 2, 2016, 2:22 AM EDT
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Nov 2, 2016, 3:06 AM EDT
poornima sekar26 reputationPosted Nov 2, 2016, 5:55 PM EDT