Public Class VendorSpecific
Dim connectionString As String = "Data Source=(LocalDB)\v11.0;Initial Catalog=SpecCompliantModule_01;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"
Dim connection As New SqlConnection(connectionString)
Dim dataadapter As SqlDataAdapter
Dim ds As New DataSet()
Private Sub VendorSpecific_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'SpecCompliantModule_01DataSet1.VendorSpecific' table. You can move, or remove it, as needed.
Me.VendorSpecificTableAdapter.Fill(Me.SpecCompliantModule_01DataSet1.VendorSpecific)
Dim sql As String = "SELECT * FROM VendorSpecific"
dataadapter = New SqlDataAdapter(sql, connection)
Dim cmdBuilder As New SqlCommandBuilder(dataadapter)
connection.Open()
dataadapter.Fill(ds, "VendorSpecific")
connection.Close()
DataGridView1.DataSource = ds
DataGridView1.DataMember = ("VendorSpecific")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
dataadapter.Update(ds, "VendorSpecific")
MessageBox.Show("Data was saved success fully")
End Sub
รบกวนด้วยนะคะ
Tag : .NET, Ms SQL Server 2008, Win (Windows App), VB.NET
Imports System.Data.SqlClient
Public Class VendorSpecific
Dim connectionString As String = "Data Source=(LocalDB)\v11.0;Initial Catalog=SpecCompliantModule_01;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"
Dim connection As New SqlConnection(connectionString)
Dim dataadapter As SqlDataAdapter
Dim ds As New DataSet()
Dim sql As String = "SELECT * FROM [dbo].[VendorSpecificMan]"
Dim cmdBuilder As SqlCommandBuilder
Private Sub VendorSpecific_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'SpecCompliantModule_01DataSet7.VendorSpecificMan' table. You can move, or remove it, as needed.
Me.VendorSpecificManTableAdapter1.Fill(Me.SpecCompliantModule_01DataSet7.VendorSpecificMan)
'TODO: This line of code loads data into the 'SpecCompliantModule_01DataSet9.VendorSpecificMan' table. You can move, or remove it, as needed.
Me.VendorSpecificManTableAdapter.Fill(Me.SpecCompliantModule_01DataSet9.VendorSpecificMan)
'TODO: This line of code loads data into the 'SpecCompliantModule_01DataSet1.VendorSpecific' table. You can move, or remove it, as needed.
dataadapter = New SqlDataAdapter(sql, connection)
connection.Open()
dataadapter.Fill(ds, "[dbo].[VendorSpecificMan]")
connection.Close()
DataGridView1.DataSource = ds.Tables
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cmdBuilder = New SqlCommandBuilder(dataadapter)
dataadapter.Update(ds, "[dbo].[VendorSpecificMan]")
MessageBox.Show("Data was saved success fully")
End Sub
Imports System.Data.SqlClient
Public Class VendorSpecific
Dim connectionString As String = "Data Source=(LocalDB)\v11.0;Initial Catalog=SpecCompliantModule_01;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"
Dim connection As New SqlConnection(connectionString)
Dim dataadapter As SqlDataAdapter
Dim ds As New DataSet()
Dim cmdBld As New SqlCommandBuilder(dataadapter)
Private Sub VendorSpecific_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim sql As String = "SELECT Vendor_Id,[Vendor_Feature Name], [Vendor_Sub Feature], [Vendor_Category Of Command], [Vendor_Command Name and Opcode] FROM [dbo].[VendorSpecificMan]"
dataadapter = New SqlDataAdapter(sql, connection)
connection.Open()
dataadapter.Fill(ds, "[dbo].[VendorSpecificMan]")
connection.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
dataadapter.Update(ds, "[dbo].[VendorSpecificMan]")
MessageBox.Show("Data was saved success fully")
End Sub
Imports System.Data.SqlClient
Public Class VendorSpecific
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim strConn, strSQL As String
Dim da As New SqlDataAdapter
Dim dt As New DataTable
Private Sub VendorSpecific_Load(sender As Object, e As EventArgs) Handles MyBase.Load
strConn = "Data Source=(LocalDB)\v11.0;Initial Catalog=SpecCompliantModule_01;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"
objConn.ConnectionString = strConn
objConn.Open()
strSQL = "SELECT * FROM [dbo].[VendorSpecificMan]"
objCmd = New SqlCommand(strSQL, objConn)
da.SelectCommand = objCmd
da.Fill(dt)
DataGridView1.DataSource = dt
da.Update(dt)
objConn.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
strConn = "Data Source=(LocalDB)\v11.0;Initial Catalog=SpecCompliantModule_01;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"
objConn.ConnectionString = strConn
objConn.Open()
strSQL = "INSERT INTO VendorSpecificMan([Vendor_Id],[Vendor_Feature Name],[Vendor_Sub Feature],[Vendor_Category Of Command],[Vendor_Command Name and Opcode]) VALUES (@[Vendor_Id],@[Vendor_Feature Name],@[Vendor_Sub Feature],@[Vendor_Category Of Command],@[Vendor_Command Name and Opcode])"
For i As Integer = 0 To DataGridView1.RowCount - 1
If Not DataGridView1.Rows(i).IsNewRow Then
objCmd = New SqlCommand(strSQL, objConn)
With objCmd
.Parameters.Add(New SqlParameter("@[Vendor_Id]", SqlDbType.Int).Value = DataGridView1.Rows(i).Cells(0).Value)
.Parameters.Add(New SqlParameter("@[Vendor_Feature Name]", SqlDbType.NVarChar).Value = DataGridView1.Rows(i).Cells(2).Value)
.Parameters.Add(New SqlParameter("@[Vendor_Sub Feature]", SqlDbType.NVarChar).Value = DataGridView1.Rows(i).Cells(3).Value)
.Parameters.Add(New SqlParameter("@[Vendor_Category Of Command]", SqlDbType.NVarChar).Value = DataGridView1.Rows(i).Cells(4).Value)
.Parameters.Add(New SqlParameter("@[Vendor_Command Name and Opcode]", SqlDbType.NVarChar).Value = DataGridView1.Rows(i).Cells(5).Value)
End With
objCmd.ExecuteNonQuery()
End If
MessageBox.Show("Data was saved success fully")
objConn.Close()
Next
End Sub
End Class