Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 9th, 2006, 12:36 AM   #1
biran
Newbie
 
Join Date: Apr 2006
Posts: 11
Rep Power: 0 biran is on a distinguished road
Question Database connectivity in C#

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
biran is offline   Reply With Quote
Old Apr 9th, 2006, 5:08 AM   #2
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
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
nnxion is offline   Reply With Quote
Old Apr 9th, 2006, 8:59 AM   #3
Pedja
Programmer
 
Join Date: Nov 2005
Location: Belgrade, Serbia & Montenegro
Posts: 31
Rep Power: 0 Pedja is on a distinguished road
Send a message via ICQ to Pedja Send a message via MSN to Pedja Send a message via Yahoo to Pedja
I think that you might be missing quotation marks around ID.Text.
Pedja is offline   Reply With Quote
Old Apr 9th, 2006, 2:13 PM   #4
BlazingWolf
Hobbyist Programmer
 
Join Date: Sep 2004
Posts: 207
Rep Power: 5 BlazingWolf is on a distinguished road
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
BlazingWolf is offline   Reply With Quote
Old Apr 10th, 2006, 4:08 AM   #5
biran
Newbie
 
Join Date: Apr 2006
Posts: 11
Rep Power: 0 biran is on a distinguished road
Thumbs up Thanks for all and new roblem

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
biran is offline   Reply With Quote
Old Apr 10th, 2006, 4:54 PM   #6
TheCodeLord
Newbie
 
Join Date: Apr 2006
Posts: 7
Rep Power: 0 TheCodeLord is on a distinguished road
Send a message via ICQ to TheCodeLord Send a message via MSN to TheCodeLord Send a message via Yahoo to TheCodeLord
Quote:
Originally Posted by biran
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
Sorry I can't understand you, what happens when you press the search button?
TheCodeLord is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:31 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC