Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a field id in my table. I am getting this error.
C#
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
v2

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:
SQL
SELECT * FROM  Tech_data...

Make sure whatever columns you have defined and mapped to be expected in the dataset are present.
 
Share this answer
 
Comments
$ultaNn 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 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'
i removed this part
C#
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
C#
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();
        }
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900