|
|
|
จะ Insert ข้อมูลลงฐานข้อมูล Access แต่ขึ้น Error ว่า Parameter @BEID has no default value |
|
|
|
|
|
|
|
Code (C#)
private void next_Click(object sender, EventArgs e)
{
try
{
for (int i = 0; i <= dataGridView1.RowCount - 1; ++i)
{
OleDbCommand cm = new OleDbCommand();
cm.Connection = CN;
cm.CommandText = "Insert Into Borrow (Sequence, Type, BWSID, BWName, BWYear, BWDepart, BEID, BEName, BEGRAN, EQquantity, BWDay, BWRDay) " +
"Values (@Sequence, @Type, @BWSID, @BWName, @BWYear, @BWDepart, @BEID, @BEName, @BEGRAN, @EQquantity, @BWDay, @BWRDay)";
cm.Parameters.Add("@Sequence", OleDbType.VarChar).Value = lblSeqNo.Text.ToString();
cm.Parameters.Add("@Type", OleDbType.VarChar).Value = bookt.Text;
cm.Parameters.Add("@BWSID", OleDbType.VarChar).Value = sid.Text;
cm.Parameters.Add("@BWName", OleDbType.VarChar).Value = sname.Text;
cm.Parameters.Add("@BWYear", OleDbType.VarChar).Value = syear.Text;
cm.Parameters.Add("@BWDepart", OleDbType.VarChar).Value = sdepart.Text;
cm.Parameters.Add(new OleDbParameter("@BEID", dataGridView1.Rows[i].Cells[0].Value));
cm.Parameters.Add(new OleDbParameter("@BEName", dataGridView1.Rows[i].Cells[1].Value));
cm.Parameters.Add(new OleDbParameter("@BEGRAN", dataGridView1.Rows[i].Cells[2].Value));
cm.Parameters.Add(new OleDbParameter("@EQquantity", dataGridView1.Rows[i].Cells[4].Value));
cm.Parameters.Add("@BWDay", OleDbType.VarChar).Value = datea.Text;
cm.Parameters.Add("@BWRDay", OleDbType.VarChar).Value = dateb.Text;
cm.ExecuteNonQuery();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
มันขึ้น Error ว่า Parameter @BEID has no default value
ต้องแก้ไขยังไงเหรอครับ
Tag : .NET, Win (Windows App), C#, Windows
|
ประวัติการแก้ไข 2020-05-24 15:33:31
|
|
|
|
|
Date :
2020-05-24 15:32:54 |
By :
KaeWalin |
View :
530 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
integer parameter ต้องแปลงเป็น object ก่อน
Code (C#)
cm.Parameters.Add(new OleDbParameter("@BEID", Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value)));
หรือ ลองใช้ ? แทน name parameter
|
|
|
|
|
Date :
2020-05-24 23:14:34 |
By :
PhrayaDev |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2020-05-25 11:54:41 |
By :
PhrayaDev |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|