C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2722
Number of posts: 5749

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
I need help Posted by stefrae15 on 25 Feb 2005 at 9:55 AM
I have written this code, and get no errors, but it doesn't insert the information into the database. I don't know why it doesn't work.Can any one help?


try
{

oleDbConnection1.Open();
oleDbDataAdapter1.InsertCommand.CommandText =
"INSERT INTO rfiddb(Customer ID, Date/Time, Item ID)"+
"VALUES ('" +
txtID.Text + "', '" +
stBarTime.Text.Substring(10,20) + "', '" +
txtItem.Text + "')";

oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();

}
catch (System.Data.OleDb.OleDbException oleException)
{
Console.WriteLine( oleException.StackTrace);
}
finally
{
oleDbConnection1.Close();
}
Report
Re: I need help Posted by Baldusarius on 25 Feb 2005 at 10:35 AM
You don't need to use a DataAdapter if your data is not coming from a DataSet. Also, string concatenation is not a good way to build a SQL statement. You should use parameterized queries instead.
OleDbCommand command = new OleDbCommand(
   "INSERT INTO rfiddb (Customer ID, Date/Time, Item ID) VALUES (?, ?, ?)", connection);"

command.Parameters.Add(txtID.Text);
command.Parameters.Add(stBarTime.Text.Substring(10,20));
command.Parameters.Add(txtItem.Text);

command.ExecuteNonQuery();


: I have written this code, and get no errors, but it doesn't insert the information into the database. I don't know why it doesn't work.Can any one help?
:
:
: try
: {
:
: oleDbConnection1.Open();
: oleDbDataAdapter1.InsertCommand.CommandText =
: "INSERT INTO rfiddb(Customer ID, Date/Time, Item ID)"+
: "VALUES ('" +
: txtID.Text + "', '" +
: stBarTime.Text.Substring(10,20) + "', '" +
: txtItem.Text + "')";
:
: oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();
:
: }
: catch (System.Data.OleDb.OleDbException oleException)
: {
: Console.WriteLine( oleException.StackTrace);
: }
: finally
: {
: oleDbConnection1.Close();
: }
:

Report
Re: I need help Posted by stefrae15 on 1 Mar 2005 at 8:19 AM
When I compile this I get The type or namespace name 'OleDbCommand' could not be found (are you missing a using directive or an assembly reference?). Does anyone know how to fix this problem?











: You don't need to use a DataAdapter if your data is not coming from a DataSet. Also, string concatenation is not a good way to build a SQL statement. You should use parameterized queries instead.
:
OleDbCommand command = new OleDbCommand(
:    "INSERT INTO rfiddb (Customer ID, Date/Time, Item ID) VALUES (?, ?, ?)", connection);"
: 
: command.Parameters.Add(txtID.Text);
: command.Parameters.Add(stBarTime.Text.Substring(10,20));
: command.Parameters.Add(txtItem.Text);
: 
: command.ExecuteNonQuery();

:

Report
Re: I need help Posted by Baldusarius on 1 Mar 2005 at 8:39 AM
The OleDbCommand class is defined in the System.Data.OleDb namespace. Either use the fully-qualified name (System.Data.OleDb.OleDbCommand) or add a using statement for System.Data.OleDb to the top of your code file.
Report
Re: I need help Posted by stefrae15 on 1 Mar 2005 at 8:42 AM
Thank you!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.