1

嘿伙计们,我面临一个小问题,我正在 vb.net 中构建一个小程序并进行访问。

我创建了一个带有插入查询的表,但是当我从查询构建器执行查询时,它可以工作并且数据被存储到数据库中,但是当我使用代码存储时,它会显示到datagridview但它不存储进入数据库。谁能帮帮我?预先感谢您的帮助。

我的代码:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


    Dim productName As String
    Dim producttype As String
    Dim batchno As String
    Dim companyname As String
    Dim expirydate As String
    Dim quantity As Integer
    Dim mrp As Double
    Dim rate As Double
    Dim margin As Double
    Dim totalvalue As Double
    Dim shelfNo As String
    Dim vat As Double
    Dim vatrate As Double
    Dim vat1 As Double
    productName = txtprodname.Text
    producttype = txtprodtype.Text
    batchno = txtbatchno.Text
    companyname = txtcompanyname.Text
    shelfNo = txtshelfno.Text
    expirydate = txtexpdate.Text
    quantity = txtquantity.Text
    mrp = txtmrp.Text

    rate = txtprodrate.Text
    vat1 = txtvat.Text
    vat = (vat1 / 100 * rate)
    vatrate = rate + vat

    margin = mrp - vatrate
    totalvalue = rate * quantity

    Me.ProductTableAdapter.InsertQueryProduct(productName, producttype, batchno, companyname, expirydate, shelfNo, vat, Date.Today, quantity, mrp, rate, margin, totalvalue)
    datagridshow2()

End Sub
4

1 回答 1

0

您正在将数据添加到 TableAdapter,但您需要将其最终确定到数据库中。

Me.Validate()
Me.YourBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.YourDataSet)
于 2013-08-05T14:16:40.880 回答