Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'UserDataSet.tbl_user' table. You can move, or remove it, as needed.
Me.Tbl_userTableAdapter.Fill(Me.UserDataSet.tbl_user)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
End Class
Tag : .NET, Ms SQL Server 2008, VS 2010 (.NET 4.x)
แล้ว ตารางผมชื่อ tbl_user และ มี user_id,username,password ครับพี่
จะ where ที่ไหนดีครับ หรือว่าที่ id เหมือนแบบ โค๊ดอันนี้ครับ Code (VB.NET)
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'UserDataSet.tbl_user' table. You can move, or remove it, as needed.
Me.Tbl_userTableAdapter.Fill(Me.UserDataSet.tbl_user)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As SqlConnection
Dim strConnString As String
strConnString = "Server=ZEROYAKI;Uid=sa;PASSWORD=1234;database=user;"
con = New SqlConnection(strConnString)
con.Open()
Dim com As New SqlCommand()
Dim sql As String
For i As Integer = 0 To DataGridView1.Rows.Count - 2
If DataGridView1.Rows(i).Cells(0).Value IsNot Nothing Then
Dim id As [String] = DataGridView1.Rows(i).Cells(1).Value.ToString()
sql = "delete from tbl_user where id='" & id & "'"
com.Connection = con
com.CommandType = CommandType.Text
com.CommandText = sql
com.ExecuteNonQuery()
End If
Next
End Sub
End Class