编辑/更新功能无法正常工作

时间:2015-04-28 06:12:17

标签: vb.net datagridview

帮助,我正在使用visual studio ultimate 2012 VB在我的应用程序上处理更新功能。

我修复了编码错误后,用f5调试程序。但是,当我试图更新datagridview上的数据时,即使消息框"数据已被更新,它也不会改变。出现。

我该如何解决这个问题?

这是更新功能的编码:

Form1中:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ClassSiswa.ubahdata(New SqlConnection, (txt_nis.Text), (txt_nisn.Text), (txt_namasiswa.Text), (cmb_kelaminsiswa.Text), (txt_kotalahir.Text), (DTP_siswa.Text), (cmb_agamasiswa.Text), (txt_beratsiswa.Text), (txt_tinggi_badan.Text))
        datagridview()
    End Sub

Private Sub UpdateDataSiswa()
    ClassSiswa.Nis = txt_nis.Text
    ClassSiswa.Nisn = txt_nisn.Text
    ClassSiswa.Nama_Siswa = txt_namasiswa.Text
    ClassSiswa.Tanggal_Lahir = DTP_siswa.Text
    ClassSiswa.Jenis_Kelamin = cmb_kelaminsiswa.Text
    ClassSiswa.Kota_Lahir = txt_kotalahir.Text
    ClassSiswa.Agama = cmb_agamasiswa.Text
    ClassSiswa.Tinggi_Badan = txt_tinggi_badan.Text
    ClassSiswa.Berat_Badan = txt_beratsiswa.Text
    ClassSiswa.Updatesiswa(ClassSiswa.opencon, (txt_nis.Text))
    datagridview()
End Sub

classSiswa:

Public Shared Sub ubahdata(ByVal _cn As SqlClient.SqlConnection, ByVal _Nis As String, ByVal _Nisn As String, ByVal _nama_siswa As String, ByVal _jenis_kelamin As String, ByVal _kota_lahir As String, ByVal _tanggal_lahir As String, ByVal _agama As String, ByVal _berat_badan As String, ByVal tinggi_badan As String)
        Dim sql As New SqlClient.SqlCommand
        sql.Connection = _cn
        sql.CommandType = CommandType.Text
        sql.CommandText = "update siswa set nis='" & Nis & "',nisn='" & Nisn & "',nama_siswa='" & Nama_Siswa & "',jenis_kelamin='" & Jenis_Kelamin & "' ,kota_lahir='" & Kota_Lahir & "',tanggal_lahir='" & Tanggal_Lahir & "'agama='" & Agama & "'berat_badan='" & Berat_Badan & "',tinggi_badan='" & tinggi_badan & "'"


        MessageBox.Show(" Data Telah Diupdate")
        ClassSiswa.closecon()
    End Sub
    Public Shared Sub Updatesiswa(ByVal _Cn As SqlClient.SqlConnection, ByVal _nis As String)
        Dim sql As SqlClient.SqlCommand
        sql = New SqlClient.SqlCommand
        sql.Connection = _Cn
        sql.CommandType = CommandType.Text
        sql.CommandText = "Update siswa Set nis = '" & Nis & "', nisn = '" & Nisn & "' where nis = '" & _nis & "'"
        sql.ExecuteNonQuery()
    End Sub

1 个答案:

答案 0 :(得分:0)

您错过了sql.ExecuteNonQuery()中的Sub ubahdata