An unhandled exception occurred during the execution of the current web request in ASP.NET

I am using WebMatrix to learn some ASP.NET. I have the following code :

        Function ShowSingleRecord(ByVal mySQL As string) As System.Data.IDataReader
        Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=H:\E_Commerce P"& _
"rac\31Jan_RevOfDB\TutECommerce\jewels.mdb"
        Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)


        Dim queryString As String = mySQL
        Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection

        dbConnection.Open
        Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

        Return dataReader
    End Function

Sub Button2_Click(sender As Object, e As EventArgs)
dim mycust as integer
mycust=(CInt(TextBox1.Text))

Dim thisSQL = "SELECT [Customer].* FROM [Customer] WHERE ([Customer].[CustID] = mycust)"
DataGrid1.DataSource=ShowSingleRecord(thisSQL)
DataGrid1.DataBind()
End Sub

-------------------------------------------------------------------------------------
and HTML code :

<html>
<head>
</head>
<body>
    <form runat="server">
        <p>
            Enter Your customer ID here:
            <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
        </p>
        <p>
            <asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
        </p>
        <p>
            <asp:Button id="Button2" onclick="Button2_Click" runat="server" Text="Show Record"></asp:Button>
        </p>
        <!-- Insert content here -->
    </form>
</body>
</html>

-------------------------------------------------------------------------------------
But receive error :

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters.


'and some long description of the error..' What could be the problem ?
redcoderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

redcoderAuthor Commented:
But then I change the line :
Dim thisSQL = "SELECT [Customer].* FROM [Customer] WHERE ([Customer].[CustID] = mycust)"
to:
Dim thisSQL = "SELECT [Customer].* FROM [Customer]"

and it works.It works when display all records (with the 2nd query), but couldn't works when I want to display single record (with the 1st query).
Elvio Lujan.Net Senior DeveloperCommented:
try...
        Function ShowSingleRecord(ByVal mySQL As string) As System.Data.DataSet
        Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=H:\E_Commerce P"& _
"rac\31Jan_RevOfDB\TutECommerce\jewels.mdb"
        Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)


        Dim queryString As String = mySQL
        Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection

        dbConnection.Open
        Dim dataReader As System.Data.DataSet = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

        Return dataReader
    End Function

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
redcoderAuthor Commented:
DOesn't work..

Basically you change the datareader to dataset is it?
I not sure if my SQL is correct or not..especially the WHERE condition... cause I see some example code use '@mycust'  instead of 'mycust'. Is there any different between them?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.