M
Muljanto
Guest
Dear All,
Until now , I have no solution in update method by using table adapter (VB.net 2015)
I have put on primary key and the other.
At this this I try to used new sql connection, like my ciode like this
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'LatihanDataSet.datamahasiswa' table. You can move, or remove it, as needed.
Me.DatamahasiswaTableAdapter.Fill(Me.LatihanDataSet.datamahasiswa)
Dim com1 As SqlConnection
com1 = New SqlConnection("data source = DESKTOP-T26PHBJ;initial catalog=latihan;integrated security=True")
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Dim a As Integer
a = DataGridView1.CurrentRow.Index
With DataGridView1.Rows.Item(a)
TextBox1.Text = .Cells(0).Value
TextBox2.Text = .Cells(1).Value
TextBox3.Text = .Cells(2).Value
End With
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim com1 As SqlConnection
com1 = New SqlConnection("data source = DESKTOP-T26PHBJ;initial catalog=latihan;integrated security=True")
Dim a As Integer
a = DataGridView1.CurrentRow.Index
With DataGridView1.Rows.Item(a)
.Cells(0).Value = TextBox1.Text
.Cells(1).Value = TextBox2.Text
.Cells(2).Value = TextBox3.Text
End With
Dim cmd As SqlCommand
cmd = New SqlCommand("update datamahasiswa set no='" & TextBox1.Text & "',nama='" & TextBox2.Text & "',alamat='" & TextBox3.Text & "', where nama='" & TextBox2.Text & "'", com1)
With cmd
.Parameters.AddWithValue("no", TextBox1.Text)
.Parameters.AddWithValue("nama", TextBox2.Text)
.Parameters.AddWithValue("alamat", TextBox3.Text)
End With
cmd.ExecuteNonQuery()
End Sub
But the the problem is
cmd.ExecuteNonQuery() show error
Please give me the correction one.
Thanks so much for your time and attention,
My best regards,
Muljanto
Continue reading...
Until now , I have no solution in update method by using table adapter (VB.net 2015)
I have put on primary key and the other.
At this this I try to used new sql connection, like my ciode like this
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'LatihanDataSet.datamahasiswa' table. You can move, or remove it, as needed.
Me.DatamahasiswaTableAdapter.Fill(Me.LatihanDataSet.datamahasiswa)
Dim com1 As SqlConnection
com1 = New SqlConnection("data source = DESKTOP-T26PHBJ;initial catalog=latihan;integrated security=True")
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Dim a As Integer
a = DataGridView1.CurrentRow.Index
With DataGridView1.Rows.Item(a)
TextBox1.Text = .Cells(0).Value
TextBox2.Text = .Cells(1).Value
TextBox3.Text = .Cells(2).Value
End With
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim com1 As SqlConnection
com1 = New SqlConnection("data source = DESKTOP-T26PHBJ;initial catalog=latihan;integrated security=True")
Dim a As Integer
a = DataGridView1.CurrentRow.Index
With DataGridView1.Rows.Item(a)
.Cells(0).Value = TextBox1.Text
.Cells(1).Value = TextBox2.Text
.Cells(2).Value = TextBox3.Text
End With
Dim cmd As SqlCommand
cmd = New SqlCommand("update datamahasiswa set no='" & TextBox1.Text & "',nama='" & TextBox2.Text & "',alamat='" & TextBox3.Text & "', where nama='" & TextBox2.Text & "'", com1)
With cmd
.Parameters.AddWithValue("no", TextBox1.Text)
.Parameters.AddWithValue("nama", TextBox2.Text)
.Parameters.AddWithValue("alamat", TextBox3.Text)
End With
cmd.ExecuteNonQuery()
End Sub
But the the problem is
cmd.ExecuteNonQuery() show error
Please give me the correction one.
Thanks so much for your time and attention,
My best regards,
Muljanto
Continue reading...