Click here to Skip to main content
15,885,870 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void button2_Click(object sender, EventArgs e)
{  
 String connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data" + @" Source = company.accdb";               
                String query = "select * from [Table] where [code] ="+txt_code.Text;
                
                DataSet ds = new DataSet();

                OleDbConnection conn = new OleDbConnection(connectionString);
 

                    conn.Open();
                    OleDbDataAdapter da = new OleDbDataAdapter(query, conn);
                    da.Fill(ds,"Table");
                    conn.Close();
                    txt_price.Text = ds.Tables["Table"].Rows[0]["price"].ToString();
                    txt_number.Text = ds.Tables["Table"].Rows[0]["number"].ToString();
                    txt_des.Text = ds.Tables["Table"].Rows[0]["description"].ToString();
                    double w = double.Parse(txt_price.Text);
                    double tax = w * 0.16;
                    txt_tax.Text = tax.ToString();
                    w = w - tax;
                    txt_w.Text = w.ToString();
}


[edit]Code block added[/edit]
Posted
Updated 11-May-13 14:47pm
v2

1 solution

You need to escape your string...

query = "SELECT * FROM [Table] WHERE [code] = '" + txt_Code.Text + "'";
 
Share this answer
 
Comments
abdallah alian 11-May-13 19:43pm    
thaaaaaaaaaaaaaaaaaaaaank alooot

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