Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.Odbc
Public Class webdata
Inherits System.Web.UI.Page
Dim strconn As String = "Driver={Microsoft Access Driver (*.mdb)};DBQ=D:/mydatainfo.mdb;"
Dim conn As New OdbcConnection
Dim sqlcomm As New OdbcCommand
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strsql As String
conn.Open()
If conn.State = ConnectionState.Open Then
strsql = "Insert into mydata(id,name,name2) values"
strsql &= "('" & TextBox1.Text.ToString & "','" & TextBox2.Text.ToString & "','" & TextBox3.Text.ToString & "')"
With sqlcomm
.Connection = conn
.CommandText = strsql
.CommandType = CommandType.Text
End With
Try
'Dim dtreader As OdbcDataReader
sqlcomm.ExecuteNonQuery()
Label1.Text = "บันทึกข้อมูลสำเร็จ"
Catch ex As Exception
Label1.Text = ex.Message
End Try
Else
Label1.Text = "ไม่ได้"
End If
End Sub
Protected Sub savedata_Click(ByVal sender As Object, ByVal e As EventArgs) Handles savedata.Click
End Sub
End Class
Dim strConnString As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("database/mydatabase.mdb")&";Jet OLEDB:Database Password=;" objConn = New OleDbConnection(strConnString)
objConn.Open()