Imports System.Data.SqlClient
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim connetionString As String
Dim connection As SqlConnection
Dim adapter As SqlDataAdapter
Dim cmdBuilder As SqlCommandBuilder
Dim ds As New DataSet
Dim changes As DataSet
Dim sql As String
Dim i As Int32
Private Property Source As DataTable
Private Property Mycn As OleDbConnection
Private Property SQLstr As Object
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Documents and Settings\Administrator\Desktop\Project\test.xls';Extended Properties=Excel 8.0;") 'เปลื่ยนC:\Documents and Settings\admin\My Documents\New Folder\aa.xls เป็นที่เก็บไฟล์ของเรา
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [ExportData$]", MyConnection) 'เปลื่ยนExportDataเป็นชื่อsheetที่ต้องการเปิด
MyCommand.TableMappings.Add("Table", "Net-informations.com")
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
DataGridView1.DataSource = DtSet.Tables(0)
MyConnection.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
connetionString = "Data Source=BPORMUFIJXUFZ2X\NICEAPPAREL;Initial Catalog=project;User ID=sa;Password=sa1234"
connection = New SqlConnection(connetionString)
sql = "select * from HOEM"
Try
connection.Open()
adapter = New SqlDataAdapter(sql, connection)
adapter.Fill(ds)
connection.Close()
DataGridView1.DataSource = ds.Tables(0)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim str1 As String = ""
Dim custsInsCmd As SqlClient.SqlCommand
custsInsCmd = Conn.CreateCommand()
str1 = " INSERT INTO HOEM=(LINE, BUYER, STYLE)VALUES(N'gh', N'th', N'yh" ')"
custsInsCmd.CommandText = str1
custsInsCmd.ExecuteNonQuery()
End Sub
End Class