string sqlInsert = "INSERT INTO Transaction " +
"(VIN, Price, TranDate, TranType) " +
"VALUES('" + VIN + "', '" + price + "', '" + aDate + "', '" + transType + "')";
// check SQL string in Output window for debugging
Console.WriteLine(sqlInsert);
myDataAdapter = new OleDbDataAdapter();
//insert new account into database
try
{
myDataAdapter.InsertCommand = new OleDbCommand(sqlInsert);
myAccessConn = ConnectionClass.getConnection();
if (myAccessConn.State == ConnectionState.Closed)
{
myAccessConn.Open();
}
myDataAdapter.InsertCommand.Connection = myAccessConn;
myDataAdapter.InsertCommand.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine("Error: Insert in DA failed");
Console.WriteLine(e);
}
coop123
0
Newbie Poster
Recommended Answers
Jump to PostWhat error are you getting
remove ' ' for price unless its of type string
"', " + price + ", '"
Shouldn't make a difference you should still get whatever error ur getting.
Jump to Posttake off all the try statements to see which line the error occurs.
shouldn't
SELECT top 1 TransID FROM Transaction order by TransID DESC
be
SELECT MAX(TransID) + 1 FROM Transaction order by TransID DESC
aDate what format do you have it in? …
Jump to PostP.S please you use Code Tagging.
your code is too hard to read like this.
Thanks
All 9 Replies
finito
46
Nearly a Posting Virtuoso
coop123
0
Newbie Poster
coop123
0
Newbie Poster
finito
46
Nearly a Posting Virtuoso
finito
46
Nearly a Posting Virtuoso
kvprajapati
1,826
Posting Genius
Team Colleague
powerbox
13
Light Poster
finito
46
Nearly a Posting Virtuoso
coop123
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.