Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  SearchSearch  Latest imagesLatest images  RegisterRegister  Log in  

 

 Add data to database

Go down 
2 posters
AuthorMessage
John




Number of posts : 7
Registration date : 2007-03-03

Add data to database Empty
PostSubject: Add data to database   Add data to database EmptySat Mar 03, 2007 6:14 pm

Add data to database

Hi
I got an error for the following code.
The error is "An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll"

The error is with the ExecuteNonQuery line.


if(textBox1.Text != "" && textBox3.Text != "")
{
dataSet1.Clear();
oleDbDataAdapter1.InsertCommand.CommandText = "INSERT INTO Final (Invoice Number, Name, Amount) VALUES ('"+textBox1.Text+"', '"+textBox2.Text+"', '"+Int32.Parse(textBox3.Text) +"')";
oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();
oleDbDataAdapter1.Fill(dataSet1);
}

What I want to do is to add values into the database, and I can't get it to work..Can anyone please help
Back to top Go down
Admin
Admin



Number of posts : 10
Registration date : 2007-03-02

Add data to database Empty
PostSubject: Re: Add data to database   Add data to database EmptySat Mar 03, 2007 6:17 pm

hi John

Try this code

if(textBox1.Text != "" && textBox3.Text != "")
{
dataSet1.Clear();
oleDbDataAdapter1.InsertCommand.CommandText = "INSERT INTO Final ([Invoice Number], [Name],[ Amount]) VALUES ("+textBox1.Text+", '"+textBox2.Text+"', "+textBox3.Text +")";
oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();
oleDbDataAdapter1.Fill(dataSet1);
}
Back to top Go down
https://programmers.forumotion.com
 
Add data to database
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
 :: Programming Languages :: C#-
Jump to: