I have a database named baiju.mdb with a table named PersData
Field Named (PNO,NAME,school,dob
i want to display data in text box in asp.net web (code in vb) as per input (PNO)in a text box and when a user writes PNO in a text box and press submit button. PNO,NAME,SCHOOL,DOB should display in three text boxes in asp.net page
1. The code i used is as under
mports System.Data.OleDb
Partial Class TEST
Inherits System.Web.UI.Page
Dim Connection As OleDbConnection
Private Sub listCard(ByVal PNO As String)
Dim con As New OleDbConnection
Dim cmd As New OleDbCommand("SELECT [PNO], [Name], [school FROM [PersData] where PNo=@PNO", con)
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@PNO", PNO)
Dim rdr As OleDbDataReader
Try
con.Open()
rdr = cmd.ExecuteReader()
While (rdr.Read())
End While
pnotxt.Text = "PNO"
nametxt.Text = "Name"
schooltxt.Text = "school"
Catch ex As Exception
Response.Write(Err.Description)
Finally
con.Close()
End Try
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If Page.IsPostBack = True Then
Dim PNO As String
If Len(txtsearch.Text) > 0 Then
PNO = txtsearch.Text
listCard(PNO)
End If
End If
End Sub
End Class
2 THE CODE I TRIED SECOND IS As under
Imports System.Data.OleDb
Partial Class info
Inherits System.Web.UI.Page
Dim connection As OleDbConnection
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
listCard()
End Sub
Public Function FixNull(ByVal dbvalue) As String
If dbvalue Is DBNull.Value Then
Return ""
Else
Return dbvalue.ToString
End If
End Function
Private Sub listCard()
Dim PNO As String = DropDownList1.SelectedValue
Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=J:\access\App_Data/AWingAMS.mdb"
Dim cn As OleDbConnection = New OleDbConnection(connectString)
cn.Open()
Dim selectString As String = "SELECT PNO, Name, school FROM PersData"
Dim cmd As OleDbCommand = New OleDbCommand(selectString, cn)
cmd.Parameters.AddWithValue("@PNO", PNO)
Dim reader As OleDbDataReader = cmd.ExecuteReader()
pnotxt.Text = "@PNO"
ranktxt.Text = "@NAME"
nametxt.Text = "@SCHOOL"
End Sub
End Class
Private Sub listCard(ByVal PNO As String)
Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=|DataDirectory|AWingAMS.mdb"
Using conn as new OleDbConnection(connectString)
Using cmd As New OleDbCommand("SELECT [PNO], [Name], [school] FROM [PersData] where PNo=@PNO", con)
cmd.Parameters.AddWithValue("@PNO", PNO)
cmd.CommandType = Data.CommandType.Text 'This is the Default value, so you can skip this line
Try
con.Open()
Using rdr = cmd.ExecuteReader()
If rdr.Read() Then
pnotxt.Text = rdr.Item("PNO")
nametxt.Text = rdr.Item("Name")
schooltxt.Text = rdr.Item("school")
End If
rdr.Close
End Using
Catch ex As Exception
Response.Write(Err.Description)
Finally
con.Close()
End Try
End Using
End Using
End Sub
Baiju EP
Member
176 Points
419 Posts
DISPLAY DATA FROM ACCESS 2003 DATABASE INTO ASP.NET WEB (CODE IN VB)
Feb 18, 2012 04:04 PM|LINK
I have a database named baiju.mdb with a table named PersData
Field Named (PNO,NAME,school,dob
i want to display data in text box in asp.net web (code in vb) as per input (PNO)in a text box and when a user writes PNO in a text box and press submit button. PNO,NAME,SCHOOL,DOB should display in three text boxes in asp.net page
1. The code i used is as under
mports System.Data.OleDb Partial Class TEST Inherits System.Web.UI.Page Dim Connection As OleDbConnection Private Sub listCard(ByVal PNO As String) Dim con As New OleDbConnection Dim cmd As New OleDbCommand("SELECT [PNO], [Name], [school FROM [PersData] where PNo=@PNO", con) cmd.CommandType = Data.CommandType.StoredProcedure cmd.Parameters.AddWithValue("@PNO", PNO) Dim rdr As OleDbDataReader Try con.Open() rdr = cmd.ExecuteReader() While (rdr.Read()) End While pnotxt.Text = "PNO" nametxt.Text = "Name" schooltxt.Text = "school" Catch ex As Exception Response.Write(Err.Description) Finally con.Close() End Try End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click If Page.IsPostBack = True Then Dim PNO As String If Len(txtsearch.Text) > 0 Then PNO = txtsearch.Text listCard(PNO) End If End If End Sub End ClassImports System.Data.OleDb Partial Class info Inherits System.Web.UI.Page Dim connection As OleDbConnection Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged listCard() End Sub Public Function FixNull(ByVal dbvalue) As String If dbvalue Is DBNull.Value Then Return "" Else Return dbvalue.ToString End If End Function Private Sub listCard() Dim PNO As String = DropDownList1.SelectedValue Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=J:\access\App_Data/AWingAMS.mdb" Dim cn As OleDbConnection = New OleDbConnection(connectString) cn.Open() Dim selectString As String = "SELECT PNO, Name, school FROM PersData" Dim cmd As OleDbCommand = New OleDbCommand(selectString, cn) cmd.Parameters.AddWithValue("@PNO", PNO) Dim reader As OleDbDataReader = cmd.ExecuteReader() pnotxt.Text = "@PNO" ranktxt.Text = "@NAME" nametxt.Text = "@SCHOOL" End Sub End Classhans_v
All-Star
35986 Points
6550 Posts
Re: DISPLAY DATA FROM ACCESS 2003 DATABASE INTO ASP.NET WEB (CODE IN VB)
Feb 19, 2012 05:51 PM|LINK
Private Sub listCard(ByVal PNO As String) Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=|DataDirectory|AWingAMS.mdb" Using conn as new OleDbConnection(connectString) Using cmd As New OleDbCommand("SELECT [PNO], [Name], [school] FROM [PersData] where PNo=@PNO", con) cmd.Parameters.AddWithValue("@PNO", PNO) cmd.CommandType = Data.CommandType.Text 'This is the Default value, so you can skip this line Try con.Open() Using rdr = cmd.ExecuteReader() If rdr.Read() Then pnotxt.Text = rdr.Item("PNO") nametxt.Text = rdr.Item("Name") schooltxt.Text = rdr.Item("school") End If rdr.Close End Using Catch ex As Exception Response.Write(Err.Description) Finally con.Close() End Try End Using End Using End Sub