หลังจากที่ไปแก้แล้วแต่ไม่สำเร็จ
ข้อความที่เกิดขึ้น Must declare the scalar variable "@id".
Code (VB.NET)
Dim constr As String = "provider=sqloledb;"
constr &= "data source=ART-PC;"
constr &= "initial catalog=book;"
constr &= "integrated security=sspi"
Dim conn As New OleDbConnection(constr)
conn.Open()
Dim ra As String
Dim sql As String
sql = "insert into book_properties(book_id,book_name)values(@id,@name)"
Dim cmd As New OleDbCommand(sql, conn)
With cmd
.Parameters.Add(New OleDbParameter("@id", txt_id.Text))
.Parameters.Add(New OleDbParameter("@name", txt_name.Text))
End With
ra = cmd.ExecuteNonQuery()
MessageBox.Show("เพิ่มข้อมูลเรียบร้อยแล้ว " & ra)
conn.Close()
Dim constr As String = "provider=sqloledb;"
constr &= "data source=ART-PC;"
constr &= "initial catalog=book;"
constr &= "integrated security=sspi"
Dim conn As New OleDbConnection(constr)
conn.Open()
Dim ra As String
Dim sql As String
sql = "insert into book_properties(book_id,book_name)values(@id,@name)"
Dim cmd As New OleDbCommand(sql, conn)
With cmd
.Parameters.AddWithValue("@id", CInt(txt_id.Text))
.Parameters.AddWithValue("@name", txt_name.Text)
End With
ra = cmd.ExecuteNonQuery()
MessageBox.Show("เพิ่มข้อมูลเรียบร้อยแล้ว " & ra)
conn.Close()