Click here to Skip to main content
15,912,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here i wrote the program. here i am getting error like this.
C#
private void GetData()
{
  con = new SqlConnection(cons);
  string query  = "Select PersonId, Lastname, Firstname, Hiredate, EnrollmentDate from Person";
  DataSet ds=new DataSet();
  da = new SqlDataAdapter(query,con);
  da.Fill(ds, "person");
  DataTable mytable = ds.Tables["Person"];
  DataRow[] row = mytable.Select("Select PersonID=1");
  gv1.DataSource = row;
  gv1.DataBind();
}

Missing operand after PersonID operator.
Posted
Updated 1-Apr-12 22:30pm
v2

Try removing the word "select" - it already knows you want to select items, that is the name of the method...
C#
DataRow[] row = mytable.Select("Select PersonID=1");
Becomes
C#
DataRow[] row = mytable.Select("PersonID=1");
 
Share this answer
 
Comments
sreekanth12 2-Apr-12 4:58am    
but it is giving error with columns it is coming
row error and has error.
OriginalGriff 2-Apr-12 5:01am    
Can you copy and paste the error message, and show which line it relates to?
sreekanth12 2-Apr-12 5:03am    
RowError HasErrors
two colummns it is displaying iam not getting please help me.
OriginalGriff 2-Apr-12 5:16am    
I am trying to help you! I just don't understand what you are saying - it is probably a language problem.
Can you give an example?
sreekanth12 2-Apr-12 5:19am    
in gridview it showing two rows one is rowerror and another is hasrow with checkbox
Hi ,
It Happens Because the way u are binding
see this example it will help you .
C#
protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(@"Data Source=.;Initial Catalog=test;Integrated Security=True");
        string statment = "select item_code, Item_name, brand, size, section, price, Material, Qty, tax, tt  from Items ";
        SqlDataAdapter da = new SqlDataAdapter(statment, con);       
        DataSet ds = new DataSet();
        da.Fill(ds);
        DataRow[] foundRows = ds.Tables[0].Select("item_code = 1", " item_code DESC", DataViewRowState.CurrentRows);
        //this is for create datatable with same schema like the orginal one .
        string statment2 = "select item_code, Item_name, brand, size, section, price, Material, Qty, tax, tt  from Items where  item_code = 0";
        SqlDataAdapter da2 = new SqlDataAdapter(statment2, con);
        DataTable dt = new DataTable();
 
        da2.Fill(dt);
        DataRow dr = dt.NewRow();   
        foreach (DataRow row in foundRows)
        {            
            dr[0] = row[0];
            dr[1] = row[1];
            dr[2] = row[2];
            dr[3] = row[3];
            dr[4] = row[4];
            dr[5] = row[5];
            dt.Rows.Add(dr);
        }
        GridView1.DataSource = dt; 
        GridView1.DataBind();
    }


ASP.NET
<div>
       <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true">
       </asp:GridView>
</div>


Best Regards
M.Mitwalli
 
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