protected void btnsubmit_Click(object sender, EventArgs e) { try { //Retrieving user id. cmd = new SqlCommand("select nuser_id from tbl_User_Info where suser_login = '"+ListBox1.SelectedValue+"'", con); DataSet ds10 = new DataSet(); DataTable dt10 = new DataTable(); SqlDataAdapter da10 = new SqlDataAdapter(cmd); da10.Fill(ds10); string uId = ds10.Tables[0].Rows[0]["nuser_id"].ToString(); int userId = Convert.ToInt32(uId); } catch (Exception ex) { } }
cmd = new SqlCommand("select nuser_id from tbl_User_Info where suser_login =@Para1", con); cmd.Parameters.AddWithValue("@Para1", ListBox1.SelectedValue); int? id = (int?)cmd.ExecuteScalar(); if(id.HasValue) { // there is value for ID, use id.Value to get the value }
protected void btnsubmit_Click(object sender, EventArgs e) { try { //Retrieving user id. cmd = new SqlCommand("select nuser_id from tbl_User_Info where suser_login = '"+ListBox1.SelectedValue+"'", con); DataSet ds10 = new DataSet(); DataTable dt10 = new DataTable(); SqlDataAdapter da10 = new SqlDataAdapter(cmd); da10.Fill(ds10); if(ds10.Tables[0].Rows.Count >0) { string uId = ds10.Tables[0].Rows[0]["nuser_id"].ToString(); int userId = Convert.ToInt32(uId); } } catch (Exception ex) { } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)