Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 C#3.0 C# ASP.NET C#4.0
I have a field id in my table. I am getting this error.
private void LoadData()
{
        con.Open();
      
        string s = "SELECT user_name FROM login" + " WHERE user_name='" + Label1.Text + "'";
        SqlCommand cmd = new SqlCommand(s, con);
        SqlDataReader Dr = cmd.ExecuteReader();
        if (Dr.Read())
        {
            con.Close();
           
            DateTime datetime = Convert.ToDateTime(Date.Text);
            SqlCommand cmnd = new SqlCommand("SELECT * FROM  Tech_data where Call_assign= @Call_assign and dateadd(dd, datediff(dd,0, [date_time]), 0) = @date_time '");
 
            cmnd.Connection = con;
            cmnd.Parameters.Add("@Call_assing", SqlDbType.VarChar).Value = Label1.Text;
            cmnd.Parameters.Add("@date_time", SqlDbType.DateTime).Value = datetime.Date;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
 
}
Posted 24-Feb-13 1:39am
Lubnash811
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'id'.
Error is quite clear. There is no column named ID when you did:
SELECT * FROM  Tech_data...
Make sure whatever columns you have defined and mapped to be expected in the dataset are present.
  Permalink  
Comments
Lubnash at 25-Feb-13 0:34am
   
this code is working perfectly in another page y??
 
protected void Button1_Click(object sender, EventArgs e)
{
DateTime date = Convert.ToDateTime(TextBox1.Text);
SqlCommand cmd = new SqlCommand("SELECT * FROM Tech_data where Call_assign = @Call_assign and dateadd(dd, datediff(dd,0, [date_time]), 0) = @date_time ");
 
cmd.Connection = con;
cmd.Parameters.Add("@Call_assign", SqlDbType.VarChar).Value = DropDownList1.SelectedValue;
cmd.Parameters.Add("@date_time", SqlDbType.DateTime).Value = date.Date;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
Tech_grid.DataSource = ds;
Tech_grid.DataBind();
}
Sandeep Mewara at 25-Feb-13 2:02am
   
Your code, your environment. If it's the exact code and the 'workflow', it should work at both the place.
 
A simple use of F11 while debugging in VS might help. To me, your 'TechGrid' & 'GridView1' does not have same columns and you refer/expect an ID column in 'GridView1'
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

i removed this part
con.Open();
      
        string s = "SELECT user_name FROM login" + " WHERE user_name='" + Label1.Text + "'";
        SqlCommand cmd = new SqlCommand(s, con);
        SqlDataReader Dr = cmd.ExecuteReader();
        if (Dr.Read())
        {
            con.Close();
        }
 
 

and placed only this part in Load
 
private void LoadData()
{
DateTime datetime = Convert.ToDateTime(Date.Text);
            SqlCommand cmnd = new SqlCommand("SELECT * FROM  Tech_data where Call_assign= @Call_assign and dateadd(dd, datediff(dd,0, [date_time]), 0) = @date_time '");
 
            cmnd.Connection = con;
            cmnd.Parameters.Add("@Call_assing", SqlDbType.VarChar).Value = Label1.Text;
            cmnd.Parameters.Add("@date_time", SqlDbType.DateTime).Value = datetime.Date;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 498
1 OriginalGriff 439
2 ChintanShukla 305
3 Richard Deeming 250
4 RyanDev 210
0 Sergey Alexandrovich Kryukov 8,901
1 OriginalGriff 7,571
2 CPallini 2,603
3 Richard MacCutchan 2,095
4 Abhinav S 1,893


Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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