Click here to Skip to main content
14,491,885 members
Rate this:
Please Sign up or sign in to vote.
Hello all, I am giving my code till now. Here my problem is i want to display One column value in textbox regarding to its id and every time a new data comes for this id i want the new data displays by textbox for this id. Please help.


protected void Page_Load(object sender, EventArgs e)
  {
      Label1.Text = DateTime.Now.ToString("MM-dd-yyyy h:mmtt");

      using (SqlConnection Conn = new SqlConnection(ConnectionString);

      {
          DataTable dt = new DataTable();
          Conn.Open();
          SqlCommand sqlCmd = new SqlCommand("SELECT * from CurrentDataCR
        ", Conn);
          SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
          sqlDa.Fill(dt);

          if (dt.Rows.Count> 0)

          {
              TextBox1.Value = dt.Rows[0]["UpStreamLevel"].ToString();
              TextBox2.Value = dt.Rows[1]["TotalDischarge"].ToString();
              TextBox3.Value = dt.Rows[2]["TotalDischarge"].ToString();
              TextBox4.Value = dt.Rows[3]["TotalDischarge"].ToString();
              TextBox6.Value = dt.Rows[4]["TotalDischarge"].ToString();
              TextBox7.Value = dt.Rows[5]["TotalDischarge"].ToString();
              TextBox8.Value = dt.Rows[6]["TotalDischarge"].ToString();
              TextBox9.Value = dt.Rows[7]["TotalDischarge"].ToString();

          }



and my sql table is as follows...

cid date1 time1 id UpLevel DownLevel Discharge
1 06/12/2015 23:15 9001 488.97 482.18 1.39
2 06/12/2015 18:00 9001 450 0 1.4
3 06/12/2015 18:00 9002 550 0 2.2
4 06/12/2015 18:00 9003 487 0 1.5
5 06/12/2015 15:00 9002 486.3 0 1.4
6 06/12/2015 18:00 9005 523.2 0 1.6
7 06/12/2015 18:00 9006 499.2 0 2.2
8 06/12/2015 18:00 9007 502 0 2.3
9 06/12/2015 16:00 9003 478 0 1.7
10 06/12/2015 17:00 9009 0 0 0.53
12 06/12/2015 19:00 9008 478 0 1.7
Posted
Updated 3-Feb-16 18:41pm
v3
Comments
koolprasadd 4-Feb-16 0:40am
   
Why don't you mention ID in where condition ? please mention which id information you want to retrieve, I think it will resolve your issue
Member 12306477 4-Feb-16 0:45am
   
I used that method, but i have differnt textboxes for differt ids, so i need more than one query command for using where condition. Can u please help me.
koolprasadd 4-Feb-16 0:59am
   
How many textboxes you have on form ? if you have different set of textboxes for each id then it may be wrong implementation
Member 12306477 4-Feb-16 1:51am
   
10 Textboxes for differnt ids.
NightWizzard 4-Feb-16 14:06pm
   
The column names you use when reading contents to the textboxes doesn't match with the column names of the table. Change UpStreamLevel to UpLevel and TotalDischarge to Discharge and it should work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100