![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2006
Posts: 11
Rep Power: 0
![]() |
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 ![]() |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Read the how to post a question thread or announcement. Please post in [code] tags.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#3 |
|
Programmer
|
I think that you might be missing quotation marks around ID.Text.
|
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Sep 2004
Posts: 207
Rep Power: 5
![]() |
The error suggest it is a something wrong with your SQL syntax and not your C# code.
'' aroudn ID.Text like Pedja said is probably the problem.
__________________
_______________________________ BlazingWolf |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Apr 2006
Posts: 11
Rep Power: 0
![]() |
Hi all,
Thanks for help, i did fixed that problem now i am having a problem with data output in datarid. i have a search button and one textbox for name and just below one datagrid when i click search button it will be display same name datas. how can i do that please help with example. thank you |
|
|
|
|
|
#6 | |
|
Newbie
|
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|