biran
April 8th, 2006, 11:54 PM
Hi all,
I puted my quetion topic like database connectivity but that question was litlebit bad so i am applying new one please help me.
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.
I puted my quetion topic like database connectivity but that question was litlebit bad so i am applying new one please help me.
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.