Hi, I want to search the dataview with a particular value,retrieve it and show it in a datagrid but its not searching appropriately. I am pasting the code for u to see....
string connstr = "Data Source=Akiii-PC;Initial Catalog=rgdb;User Id = sa;password = 12345";
SqlConnection conn = new SqlConnection(connstr);
SqlCommand cmd;
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
DataView dv;
try
{
conn.Open();
cmd = new SqlCommand("select * from reg_table", conn);
sda.SelectCommand = cmd;
sda.Fill(ds, "reg_table");
sda.Dispose();
cmd.Dispose();
conn.Close();
dv = new DataView(ds.Tables[0]);
dv.Sort = "name";
int index = dv.Find("12333");
if(index == -1)
{
Response.Write("no result");
}
else
{
GridView1.DataSource = dv;
GridView1.DataBind();
//Response.Write(dv[index]["Product_id"].ToString() + " " + dv[index]["Product_Name"].ToString());
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
12333 is the value that i want to search in the dataview which has been populated by dataset but it cannot find any result.
Please help me on this.....
Am i doing something wrong here...?
Thanks and Regards
Akiii