I changed my host provider from godaddy to webhosting world, and now suffering the problem regarding the access of mdb database via vb code of my aspx page.
The following is my code created using Microsoft visual web developer software. It works well when run in my computer, and when deployed to godaddy. but when i uploaded it to webhosting world, it failed to work.
I contacted the support team of my new host provider, still can't resolve the problem. would appreciate if anyone can enlighten me....
Imports System.Data.OleDb
Partial Class _Default Inherits System.Web.UI.Page
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'test write
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("~/App_Data/number_database.mdb"))
cn.Open()
cmd = New OleDbCommand()
cmd.Connection = cn
cmd.CommandText = "INSERT INTO testing (a_name, a_id) VALUES (@a_name, @a_id)"
cmd.Parameters.AddWithValue("@a_name", TextBox1.Text)
cmd.Parameters.AddWithValue("@a_id", TextBox2.Text)
cmd.ExecuteNonQuery()
cn.Close()
TextBox1.Text = ""
TextBox2.Text = ""
'test read
Dim my_namelist(100), myid(100) As String
Dim counter_read As Integer
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("~/App_Data/number_database.mdb"))
cn.Open()
cn.Open()
cmd = New OleDbCommand("SELECT * FROM testing ", cn)
Dim reader As OleDbDataReader
reader = cmd.ExecuteReader()
Do While reader.Read()
my_namelist(counter_read) = reader.GetString(1)
myid(counter_read) = reader.GetString(2)
counter_read = counter_read + 1
Loop
reader.Close()
TextBox3.Text = "database list" & vbNewLine & vbNewLine
For a = 0 To counter_read
TextBox3.Text = TextBox3.Text & my_namelist(a) & vbTab & vbTab & myid(a) & vbNewLine
Next
End Sub
End Class
Aucun commentaire:
Enregistrer un commentaire