Click here to Skip to main content
15,891,763 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello..
i have problem to display data from access data to text box but dont display any think i have vs2013 and the code below:
aspx:

ASP.NET
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication14.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Database1ConnectionString %>" ProviderName="<%$ ConnectionStrings:Database1ConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [Table1]"></asp:SqlDataSource>
    </form>
</body>
</html>



vb.net:
VB
Imports System.Data
Imports System.Data.SqlClient
Public Class WebForm1
    Inherits System.Web.UI.Page

    Private Sub getData(ByVal user As String)
        Dim dt As New DataTable()
        Dim connection As New SqlConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Mohammed\Documents\Database1.mdb")
        connection.Open()
        Dim sqlCmd As New SqlCommand("SELECT * from TABLE1 WHERE UserID = @username", connection)
        Dim sqlDa As New SqlDataAdapter(sqlCmd)
        sqlCmd.Parameters.AddWithValue("@username", user)
        sqlDa.Fill(dt)
        If dt.Rows.Count > 0 Then
            TextBox1.Text = dt.Rows(0)("ID").ToString
            TextBox2.Text = dt.Rows(0)("PhoneNumber").ToString
            Label1.Text = dt.Rows(0)("ID").ToString
            Label2.Text = dt.Rows(0)("PhoneNumber").ToString
        End If
        connection.Close()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Not Page.IsPostBack Then
            getData(Me.User.Identity.Name)
        End If
    End Sub
End Class


What I have tried:

i change th database and change the code but get error and i get this code but not work .

Thanks Advance
Posted
Updated 9-Jul-17 21:58pm
v2
Comments
ZurdoDev 8-Jul-17 16:48pm    
And the error is?
Mohammed.iq 9-Jul-17 11:05am    
there is no error but the data not display.. thanks for your replay

Look like you will be getting " Keyword not supported: 'provider'. " error since the application is using SqlConnection class to access the Microsoft Access database. It should utilize the OleDbConnection class.

Here how the code should look like.
VB
Private Sub getData(ByVal user As String)

    Dim dt As New DataTable()
    ' Dim connection As New SqlConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Mohammed\Documents\Database1.mdb")
    Dim connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Mohammed\Documents\Database1.mdb")
    connection.Open()
    ' Dim sqlCmd As New SqlCommand("SELECT * from TABLE1 WHERE UserID = @username", connection)
    Dim sqlCmd As New OleDbCommand("SELECT * from TABLE1 WHERE UserID = @username", connection)
    'Dim sqlDa As New SqlDataAdapter(sqlCmd)
    Dim sqlDa As New OleDbDataAdapter(sqlCmd)
    sqlCmd.Parameters.AddWithValue("@username", user)
    sqlDa.Fill(dt)
    If dt.Rows.Count > 0 Then
        TextBox1.Text = dt.Rows(0)("ID").ToString
        TextBox2.Text = dt.Rows(0)("PhoneNumber").ToString
        Label1.Text = dt.Rows(0)("ID").ToString
        Label2.Text = dt.Rows(0)("PhoneNumber").ToString
    End If
    connection.Close()
End Sub


By the way is the SqlDataSource on the .aspx redundant?
 
Share this answer
 
v2
Comments
Mohammed.iq 9-Jul-17 8:39am    
thank you for your replay.. i get many error.. is i need to add reference for your code.
Mohammed.iq 9-Jul-17 8:57am    
i add reference but i get this error at sqlDa.Fill(dt) ..
Debugger:Stopped at Exception: ExecuteCommandTextErrorHandling
An exception was caught by the debugger, and user settings indicate that a break should occur.
Time: 7/9/2017 3:48:37 PM
Thread:Worker Thread[17196]
Bryian Tan 9-Jul-17 19:07pm    
Hmm. Interesting. Are you using Access Database? Make sure the code has this name space on top
Imports System.Data.OleDb
. Did you check if the user or Me.User.Identity.Name has value in it?
Mohammed.iq 10-Jul-17 11:42am    
thanks friend for your replay.. yes there is no connection..
its stop at Dim connection As New OleDbConnection("DatabaseConnectionString")
connection.Open()

and i add sqldatasource tool and get name string in the code but the sum problem..
thanks again for your time
Use "Configure Data Source.." option to construct connection string to your access database. you would see this option after you add SqlDataSource to your aspx page in design view and select it. Use "New Connection..." and "Microsoft Access Database File" options respectively from the dialog.
 
Share this answer
 
Comments
Mohammed.iq 10-Jul-17 11:43am    
thanks friend for your replay.. i do that but the same problem..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900