ASP.NET - please any help?? - Asked By mani on 14-Dec-11 01:32 AM

hi..please anybody helpme..
i have unique number values in my table..
and i will getany number of that value in session..
and i have to read all those record of that values from table and bind it in gridview...
Jitendra Faye replied to mani on 14-Dec-11 01:40 AM
Use this code-

protected void GetDetails_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("con string ");
SqlDataAdapter da;
string mySQL = "SELECT * FROM emptable where empid='" + Convert.ToString(Session["id"]) + "'";
da = new SqlDataAdapter(mySQL, con);
con.Open();
DataSet ds = new DataSet();
da.Fill(ds);


if(ds.Tables[0].Rows.Count>0)
{
//Now Filling Details-


GridvIew1.DataSource=ds;
GridvIew1.DataBind();
}
}


Try this code and let me know.

mani replied to Jitendra Faye on 14-Dec-11 01:43 AM
hi i have multiple unique value in that session separated with comma,,
i need to split it and get all those record from table..
dipa ahuja replied to mani on 14-Dec-11 02:27 AM
You have to use the IN clause

For eX;


void getReuslt()
{
  string Ids = Session["values"].ToString();
  SqlDataAdapter da = new SqlDataAdapter("select * from tabl1 where Ids IN(" + Ids + ")""connString");
  DataTable dt = new DataTable();
  da.Fill(dt);
 
  //bind Gridview
 
}

Jitendra Faye replied to mani on 14-Dec-11 03:33 AM
You can split like this-

string s = "a,s,d,f,g";

string[] words = s.Split(',');
foreach (string word in words)
{
   Console.WriteLine(word);
}

Try this and let me know.