Click to See Complete Forum and Search --> : Help Me Access DataBase


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.

logan
April 9th, 2006, 01:21 AM
Try this:

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+")";

biran
April 9th, 2006, 01:39 AM
Hi logan,
Its same problem.

Syrix
April 9th, 2006, 10:52 PM
remove the second back slash :)

string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data\reco.mdb";

aniskhan
April 10th, 2006, 12:56 AM
try it like this
"INSERT INTO Students VALUES(...........)";