0
を働いていないLAST_INSERT_IDすることについては、私が持っているものです...ここで私を助けてください
問題は、あなたのテーブルにauto-increment
変数を持っている場合last_insert_id not working
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
CMD.CommandText = "INSERT product_tbl (stockno, product_desc, price, Unit) VALUES (@stockno, @catid, @compid, @desc, @price, @unit);SELECT LAST_INSERT_ID()"
CMD.Parameters.AddWithValue("@stockno", txtstockno.Text)
CMD.Parameters.AddWithValue("@desc", txtdesc.Text)
CMD.Parameters.AddWithValue("@price", txtprice.Text)
CMD.Parameters.AddWithValue("@Unit", txtUnit.Text)
Dim ProductID As Int32
Try
ProductID = (System.Convert.ToInt32(CMD.ExecuteScalar))
Catch ex As Exception
TR.Rollback()
CN.Close()
Throw ex
End Try
'the code above are working just fine but when it comes the second insert to
'inventory_tbl it doesn't work at all. am i missing something or did wrong?
CMD.CommandText = "INSERT invetory_tbl (productid, qty) VALUES(@productID, @qty)"
CMD.Parameters.Clear()
CMD.Parameters.AddWithValue("@orderID", ProductID)
' CMD.Parameters.AddWithValue("@qty", txtqty.Text)
Try
CMD.ExecuteNonQuery()
Catch ex As Exception
TR.Rollback()
Throw ex
End Try
TR.Commit()
CN.Close()