-
web application
Hy,
I need to know how can I connect my web form to an access database.
Is it by edditing the web.config.
or by creating an ordinar:
OledConnection
OledbDataadapter
and a Dataset??
I tried these methode but got errors in the dataadapter.fill.
Please it's urgent tell me what to do.
-
exmaple of getting access data into a dataset
Code:
Public rptCatagory As Repeater
Dim myDS As New DataSet
Dim myConn As OleDbConnection
Dim myCommand As OleDbDataAdapter
Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" & System.Web.HttpContext.Current.Server.MapPath("test.mdb")
Dim strSQL As String
Private Sub Page_Load(ByVal sender As Object, e As EventArgs)
' Get Catagory listing from db
strSQL = "SELECT c.ID, c.Catagory, c.PostCount, c.LastPostDate, c.Description, u.Username, u.ID AS UserID FROM Catagories AS c INNER JOIN Users AS u ON c.LastPostBy = u.ID"
' Populate the Dataset from the SQL statement
' Start Connection to ADO source
myConn = New OleDbConnection (strConnString)
' Run the Sql statement and get the Data into the DataAdapter
myCommand = New OleDbDataAdapter(strSQL, myConn)
' Fill the DataSet and name the table
myCommand.Fill(myDS, "Catagory")
myConn.Close()
' Now set the DataGrid's source to the Dataset and bind it
rptCatagory.DataSource = myDS.Tables("Catagory").DefaultView
rptCatagory.DataBind()
End Sub
-
Thanks
Thank you Cander,
the code you gave me, solved the problem, but how can I bind my data to a text fields, so that the user can navigate through the database?
Please tell me if it is possible, and how can we do it.
Thanks for your help.
-
not sure what you mean by navigate in a textbox?!?
-
Navigation
Hi, once again.
What I meant in navigation, is that I want to link a textbox to a field of my dataset, and went I navugate the data set by presseing the: First, Next, Previous, and Last buttons, data must directly changed in the text box.
We use to be able to do this in a windows application by setting the DataBinding Property to the DataSet Field I want, but since I am not using the wizard and creating a dataset object in my project, I couldn't do this in code.
So please help me in this it's really very urgent.