Click here to Skip to main content
12,074,926 members (56,796 online)
Rate this:
 
Please Sign up or sign in to vote.
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 11-May-13 14:16pm
Edited 11-May-13 15:47pm
Nelek90.6K
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You need to escape your string...

query = "SELECT * FROM [Table] WHERE [code] = '" + txt_Code.Text + "'";
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160208.1 | Last Updated 11 May 2013
Copyright © CodeProject, 1999-2016
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