Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi all,
i have a AccessDatabase and all fields data type are text and i am adding data from C# form window. when i click save button its giving me ERROR IN INSERT INTO STATEMENT.
I did like this:
private void SaveAndAddnew_Click(object sender, EventArgs e)
{try
{
string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data\\reco.mdb";
OleDbConnection myConn = new OleDbConnection(strConn);
myConn.Open();
string strInsert = "INSERT INTO Students(ID,Student_Name,Gender,Phone_No,Year,Father_Name)VALUES("+ID.Text+",'" + Student_Name.Text + "','" + Gender.Text + " ',' " + Phone_Number.Text + " ','" + Year.Text + "','" + Father_Name.Text+"')";
OleDbCommand inst = new OleDbCommand(strInsert, myConn);
inst.ExecuteNonQuery();
myConn.Close();
}
catch (Exception ed)
{
MessageBox.Show("Error in Saving\n" + ed.ToString(), "Error");
}
}But I am getting syntax error at "INSERT INTO STATEMENT
Where is the problem please help me tooo.biran

The only syntax issue that I can see is that there are leading and trailing spaces inside the PhoneNumber field. I don't know if adding those spaces exceeds the alloted space for the phone number, but that is the only thing that looks sort of weird to me.
Paste the entier error message (use Console.WriteLine(ed.Message); within your Catch block so that you don't have to retype it.
Chi
They mostly come at night...mostly.

Hello,
Because of all database fields are text datatype, so ID is also text data type ?
If ID is text data , you miss ' character.
Vunguyen

![]() |
Writing Software
|
Null error message
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |