我努力讓此功能工作,因爲它保持了INSERT INTO
陳述但是相同的代碼工作的另一頁/表單中的標記語法錯誤由於完成...誰能幫幫我?保存函數形式而不是一個語法錯誤
它似乎有另一種形式在這個問題上,現在也不過,我看不出有什麼不對的地方......
private void btnAssign_Click(object sender, EventArgs e)
{
string LocID = txtLocID.Text;
string AssID = txtAssID.Text; // declaing instance names
string StaID = txtID.Text;
string Sku = txtSKU.Text;
if (txtLocID.Text.Length < 1) // validating a text box
{
MessageBox.Show("Please Enter an Location ID");
}
else if (txtAssID.Text.Length < 1)
{
MessageBox.Show("Please Enter an Assignment ID");
}
else if (txtID.Text.Length < 1)
{
MessageBox.Show("Please Enter a Staff ID");
}
else if (txtSKU.Text.Length < 1)
{
MessageBox.Show("Please Enter a Product SKU");
}
else
{
try
{
int Loc;
Cons.ConnectionString = ConnectionDetail.Warehouse;
OleDbCommand cmds = new OleDbCommand();
Cons.Open();
cmds.CommandText = @"Insert into Assign (Location ID, Assign ID, Staff ID, SKU) VALUES (@LocID, @AssID, @StaID, @Sku)";
cmds.Connection = Cons;
cmds.Parameters.AddWithValue("LocID", LocID);
cmds.Parameters.AddWithValue("AssID", AssID);
cmds.Parameters.AddWithValue("StaID", StaID);
cmds.Parameters.AddWithValue("Sku", Sku);
Loc = cmds.ExecuteNonQuery();
if (Loc > 0)
MessageBox.Show("Location has successfully been assigned a product and Saved");
}
catch (Exception err)
{
MessageBox.Show("error:" + Environment.NewLine + err.Message);
}
finally
{
if (Cons.State == ConnectionState.Open)
Cons.Close();
}
}
}
能否請您發佈錯誤消息嗎? –
錯誤:INSERT INTO語句中的語法錯誤。 –
列名中有空格。我認爲你需要解決這個問題。 – crunchy