Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello I'm still getting this error and I try different solutions but it's not work !
Here are my code

I put the connection string in app.config file like this :

C#
    <connectionStrings>
    <add name="ComputerManagement" 
    connectionString= "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=..... ; Integrated Security=false"/>
  </connectionStrings>
</configuration>


and in the button_click in the form I put the following code :

C#
try
           {
               OleDbConnection conn = new OleDbConnection(GetConnectionString());
               OleDbCommand command = new OleDbCommand();
               command.CommandType = CommandType.Text;

               command.CommandText = "INSERT INTO Clients(C_name,C_phone ,C_mob ,C_add , C_email ,C_account) VALUES ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4 + "','" + textBox5.Text + "','" + textBox6.Text + "')";
               command.Connection = conn;
               conn.Open();
               command.ExecuteNonQuery();
               conn.Close();
           }
           catch (Exception) { throw; }
Posted
Comments
ZurdoDev 19-Feb-13 9:02am    
First off, you need to research SQL injections if this is actual production code. Anyone who knows a little bit of SQL could run your app and delete your tables, as an example. However, what does commandtext look like after the values are inserted in? What does the actual string look like that you are sending to Access?
Richard MacCutchan 19-Feb-13 9:29am    
+ textBox4
You forgot to use the .Text property. Also, as ryanb31 says, you should not be doing it this way, but by using proper parameterised commands.

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