Vb.net更新datagrid查看问题

时间:2016-03-22 15:39:38

标签: mysql vb.net

我构建一个p.o.s并且我尝试更新datagridview但是每次我输入新条目时我都会获得数据网格视图我试图刷新数据网格但没有成功。

   Dim Query As String
        Query = "insert into baza.artikli(barkod,naziv,kupovna,prodazna,opis,kolicina,ddv,makpr) values ('" & TextBoxBarkod.Text & "','" & TextBoxNaziv.Text & "','" & kupovna & "','" & prodazna & "','" & TextBoxOpis.Text & "','" & TextBoxKolicina.Text & "','" & ddv & "','" & makpr & "')"
        COMMAND = New MySqlCommand(Query, konekcija)
        READER = COMMAND.ExecuteReader

如何从这里更新数据集我将它与mysql一起使用

1 个答案:

答案 0 :(得分:0)

如果你想填充数据集并在网格后显示数据,这里有一个例子:

我使用过MS SQL SERVER,可以使用MySql

 Public Function FillDataSet(query As String, ByVal ParamArray para() As Object) As DataTable

     dim _transaction As SqlTransaction
     Dim _command As SqlCommand

    _command = New SqlCommand(query, yourConnection)

    _ds = New DataSet
    _sqlda = New SqlDataAdapter(_command )
    _command.Transaction = _transaction

    For i = 0 To para.Count - 1
        _command.Parameters.AddWithValue("@" & i, para(i))
    Next

    _sqlda.Fill(_ds)

   return _ds.tables(0)

   End Function

称之为

 dataGridView1.datasource = FillDataSet(yourQuery, yourParam)