Computing.Net > Forums > Programming > Database connectivity in C#

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Database connectivity in C#

Reply to Message Icon

Name: biran
Date: April 8, 2006 at 21:18:52 Pacific
OS: Win 2003 Server
CPU/Ram: 2.8/512
Product: Intel
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Chi Happens
Date: April 10, 2006 at 05:52:12 Pacific
Reply:

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.


0

Response Number 2
Name: ntvmt98
Date: April 21, 2006 at 01:17:14 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Writing Software Null error message



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Database connectivity in C#

database connection in c++ www.computing.net/answers/programming/database-connection-in-c/10250.html

Database Connectivity in VB.NET www.computing.net/answers/programming/database-connectivity-in-vbnet/12382.html

Database connection with C www.computing.net/answers/programming/database-connection-with-c/3917.html