Click here to Skip to main content
11,702,939 members (62,295 online)
Rate this: bad
good
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 13:16pm
Edited 11-May-13 14:47pm
Nelek73.8K
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 at 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
0 Maciej Los 415
1 Sergey Alexandrovich Kryukov 325
2 OriginalGriff 260
3 CHill60 120
4 Andy Lanng 119
0 OriginalGriff 8,379
1 Sergey Alexandrovich Kryukov 7,587
2 CPallini 4,947
3 Maciej Los 4,501
4 Mika Wendelius 3,566


Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 11 May 2013
Copyright © CodeProject, 1999-2015
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