I am trying to call a INSERT INTO query but I am getting a Parameter error
Parameter_ has no default value...
private void button2_Click(object sender, System.EventArgs e)
{
try
{
//create SQL query to insert rowoleDbDataAdapter2.InsertCommand.CommandText =
"INSERT INTO Company (" + "Client, [Action], Stake," + "Market, OpeningPrice, ClosingPrice, [OpeningDate], [ClosingDate]" + ") VALUES ('" +listBox1.Text +
"','" +listBox2.Text +
"', " +textBoxStake.Text +
" , '" +textBoxMarket.Text +
"' , " +textBoxOpenPrice.Text +
" , " +textBoxClosePrice.Text +
" , " +textBoxOpenDate.Text +
" , " +textBoxCloseDate.Text +
")";//notify user that query is being sent
textBoxStatusQuery.Text +=
"\r\nSending query: " +oleDbDataAdapter2.InsertCommand.CommandText +
"\r\n"; //send queryoleDbDataAdapter1.InsertCommand.ExecuteNonQuery();
textBoxStatusQuery.Text +=
"\r\nQuery successful\r\n";}
catch (System.Data.OleDb.OleDbException oleException){
Console.WriteLine(oleException.StackTrace);textBoxStatusQuery.Text += oleException.ToString();
}
}
I have checked the insertcommand generated by VS8 and copied it underneath
// oleDbSelectCommand2 // this.oleDbSelectCommand2.CommandText = "SELECT IDPortfolio, Client, OpeningDate, ClosingDate, [Action], Stake, Market" + ", OpeningPrice, ClosingPrice\r\nFROM Company"; // // oleDbInsertCommand2 // this.oleDbInsertCommand2.CommandText = "INSERT INTO `Company` (`Client`, `OpeningDate`, `ClosingDate`, `Action`, `Stake`," + " `Market`, `OpeningPrice`, `ClosingPrice`) VALUES ( , , , , , , , )"; this.oleDbInsertCommand2.Parameters.AddRange(new System.Data.OleDb.OleDbParameter[] { new System.Data.OleDb.OleDbParameter("Client", System.Data.OleDb.OleDbType.VarWChar, 0, "Client"), new System.Data.OleDb.OleDbParameter("OpeningDate", System.Data.OleDb.OleDbType.Date, 0, "OpeningDate"), new System.Data.OleDb.OleDbParameter("ClosingDate", System.Data.OleDb.OleDbType.Date, 0, "ClosingDate"), new System.Data.OleDb.OleDbParameter("Action", System.Data.OleDb.OleDbType.VarWChar, 0, "Action"), new System.Data.OleDb.OleDbParameter("Stake", System.Data.OleDb.OleDbType.Integer, 0, "Stake"), new System.Data.OleDb.OleDbParameter("Market", System.Data.OleDb.OleDbType.VarWChar, 0, "Market"), new System.Data.OleDb.OleDbParameter("OpeningPrice", System.Data.OleDb.OleDbType.Long, 0, "OpeningPrice"), new System.Data.OleDb.OleDbParameter("ClosingPrice", System.Data.OleDb.OleDbType.Long, 0, "ClosingPrice")}); //
This was generated by Visual Studio,
And also I would like to know what would be the command to update the database too as I have the same function on another form and its working fine (addclient) but the database does not get updated - it says query succesfull, but no change on the back end. Any idea
Thanks guys