I’m using Web Developer 2010, ASP.NET with the VB.NET programming language and a MS-Access database (.mdb).
What I want to do is get all the data from a table called User (i.e. all the columns) where Username = ____, and then put the values in from the fields into text boxes so they can be edited. This is to make a ‘My Account’ page so that a user viewing the website can change his address, password etc.
I’m stuck at getting the data from the fields for each specific username.
What I’ve done so far is this, but doesn’t work:
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Data
Partial Class Account
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim tUsername As String = Session("Username")
Dim tPassword As String = Session("Password")
Dim conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Brian\Documents\Visual Studio 2010\WebSites\PetLandia\App_Data\db.mdb")
Dim cmd As OleDbCommand = New OleDbCommand("SELECT [Email], [CustomerName], [CustomerSurname], [Address], [Country], [TelNo], [Username], [Password] FROM [User] WHERE Username=?", conn)
DataSet(dst = New DataSet)
cmd.Parameters.AddWithValue("@Username", tUsername)
conn.Open()
Dim reader As OleDbDataReader = cmd.ExecuteReader
If (reader.Read()) Then
lblName.Text = reader.GetValue(4).ToString
lblSurname.Text = reader.GetValue(5).ToString
lblUsername.Text = reader.GetValue(9).ToString
txtAddress.Text = reader.GetValue(6).ToString
txtCountry.Text = reader.GetValue(7).ToString
txtEmail.Text = reader.GetValue(2).ToString
conn.Close()
End If
End Sub
End Class
Error message:
Parameter ?_1 has no default value.
at
Dim reader As OleDbDataReader = cmd.ExecuteReader
Any help ?
Your index numbers are not lining up with your query statement.
Try