Click here to Skip to main content
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 14:16pm
Edited 11-May-13 15:47pm
Nelek59.4K
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 Mathew Soji 274
1 BillWoodruff 270
2 Afzaal Ahmad Zeeshan 244
3 Sergey Alexandrovich Kryukov 240
4 Raul Iloc 160
0 OriginalGriff 6,219
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,103
3 Manas Bhardwaj 4,549
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 11 May 2013
Copyright © CodeProject, 1999-2014
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