Sub Page_Load(sender As Object, e As EventArgs)
Dim objConn As New OleDbConnection
Dim dtAdapter As OleDbDataAdapter
Dim dt As New DataTable
Dim strConnString As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source="&Server.MapPath("MyXls/MyExcelDB.xls")&";Extended Properties=Excel 8.0;"
objConn = New OleDbConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM [Sheet1$]"
dtAdapter = New OleDbDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
'*** BindData To DataGrid ***'
Me.myDataGrid.DataSource = dt
Me.myDataGrid.DataBind()
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
End Sub
Dim connetionString As String
Dim connection As SqlConnection
Dim adapter As New SqlDataAdapter
Dim sql As String
connetionString = "Data Source=ServerName;Initial Catalog=MyDatabase;User ID=UserName;Password=Password"
connection = New SqlConnection(connetionString)
sql = "insert into product (Product_id,Product_name,Product_price) values(1,'Product Name',500)"
Try
connection.Open()
adapter.InsertCommand = New SqlCommand(sql, connection)
adapter.InsertCommand.ExecuteNonQuery()
MsgBox("Row inserted !! ")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Dim objConn As New OleDbConnection
Dim dtAdapter As OleDbDataAdapter
Dim dt As New DataTable
Dim strConnString As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source="&Server.MapPath("MyXls/MyExcelDB.xls")&";Extended Properties=Excel 8.0;"
objConn = New OleDbConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM [Sheet1$]"
dtAdapter = New OleDbDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
'*** BindData To DataGrid ***'
Me.myDataGrid.DataSource = dt
Me.myDataGrid.DataBind()
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Dim connetionString As String
Dim connection As SqlConnection
Dim adapter As New SqlDataAdapter
Dim i As Integer
Dim sql As String
connetionString = "Data Source=ServerName;Initial Catalog=MyDatabase;User ID=UserName;Password=Password"
connection = New SqlConnection(connetionString)
connection.Open()
For i = 0 To dt.Rows.Count - 1
sql = "insert into product (Product_id,Product_name,Product_price) values('" & dt.Rows(i)(0) & "','" & dt.Rows(i)(1) & "','" & dt.Rows(i)(2) & "')"
adapter.InsertCommand = New SqlCommand(sql, connection)
adapter.InsertCommand.ExecuteNonQuery()
Next
connection.Close()