如何在DataGridView中编辑和删除数据?

我正在用VB.NET开发一个桌面应用程序,我想在其中编辑、删除和添加DataGridView中的新行。我怎样才能做到这一点呢?

从字符串“更新dbo.Trans集BCode='1',”转换为类型'Double‘时出现错误“”无效。“

我尝试过的代码如下:

con =新建SqlConnection("Data Source=USER\SQLEXPRESS;Initial Catalog=Sap;Integrated Security=True")

    If (TbCode.Text = "" Or TbItem.Text = "" Or TbWgt.Text = "") Then
        MessageBox.Show("Please fill all the columns")
    Else
        con.Open()

        cmd1 = New SqlCommand("Update  dbo.Trans set BCode='" + TbCode.Text + "',BName='" + Label2.Text + "',ICode='" + TbItem.Text + "',IName='" + Label3.Text + "',Qty='" + TbQty.Text + "',Weight='" + TbWgt.Text + "',RWeight='" + Label4.Text + "',Rate='" + Rate + "'  where date=@date and depot=@depot and BCode=@bcode and Icode=@icode", con)
        cmd1.Parameters.AddWithValue("@depot", TbDepot.Text)
        cmd1.Parameters.AddWithValue("@icode", TbItem.Text)
        cmd1.Parameters.AddWithValue("@date", IDate.Text)
        cmd1.Parameters.AddWithValue("@bcode", TbCode.Text)
        cmd1.ExecuteNonQuery()


    End If


    con.Close()

    Call Fillgrid()
    Call emptyfun()

End Sub

转载请注明出处:http://www.xgclsm.com/article/20230526/1728919.html