I need to make a project in ASP.NET that, among other functions will be able to add new data to two tables at once.
One table is named 'products' with columns 'name' and 'id' as PK
The other one is named 'auctions' with columns 'bidValue' and 'productId'.
If someone could tell me what am I doing wrong in this code. When I click the button it gives an error page with this text:
Incorrect syntax near ','.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near ','.
Source Error:
Line 86: comm.Parameters.AddWithValue("@valueOfBid1", valueOfBid);
Line 87:
Line 88: ***comm.ExecuteNonQuery();***
Line 89: }
Line 90: }
Here is my code:
public void makeBid(string nameOfProduct, int valueOfBid)
{
string query = @"INSERT INTO products.name, auctions.bidValue VALUES @nameOfProduc,
@valueOfBid1
FROM products
INNER JOIN auctions ON products.id = auctions.productId";
using (SqlConnection conn = DbBroker.conn())
{
using (SqlCommand comm = new SqlCommand(query, conn))
{
comm.Parameters.AddWithValue("@nameOfProduc", nameOfProduct);
comm.Parameters.AddWithValue("@valueOfBid1", valueOfBid);
comm.ExecuteNonQuery();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Auction1 newBid = new Auction1();
string productName = TextBox1.Text.Trim().ToString();
string lbItem = ListBox1.SelectedValue;
int bidValue = Int32.Parse(lbItem);
newBid.makeBid(productName, bidValue);
}