ส่วนอันนี้หน้า form ที่ออกแบบไว้คะ ตอนใส่ข้อมูล Id ไม่ขึ้นให้น่ะคะ ต้องทำยังไงคะ
โค้ดทั้งหมดที่เขียนไว้คะ Code (VB.NET)
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
'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.
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
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim hom As Form
hom = HOME
HOME.Show()
Me.Hide()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim specComp As Spec_complaint_module
specComp = Spec_complaint_module
Spec_complaint_module.Show()
Me.Hide()
End Sub
End Class
Tag : .NET, Ms SQL Server 2008, Win (Windows App), VB.NET