none
Retrieving data from Access

    Question

  • Hey all,

    I'm not too sure if this the right area to post this in, but anyway, I'm currently having trouble working out how to retreive data from Access in ASP.NET (Visual Studio 2005),  but the catch is that I'm not allowed to use the Grid View object.

    Details:
    The website page has multiple textboxes, (one is for saying which record to retrieve from the DB, the rest are to be filled in).
    Retrieving data from a table called Customers to place in a dataset, it is at this point I get the following error:

        OleDBException:
        No value given for one or more required parameters.

    CODE:
    Protected Sub cmdRETRIEVE_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdRETRIEVE.Click  
            Dim connString = ConfigurationManager.ConnectionStrings("DVDeasyConn").ConnectionString  
            ' Create DB connection  
            Dim DbConn As OleDbConnection = New OleDbConnection(connString)  
            'create Insert Query  
            Dim RetrieveCmdQuery As String = _ 
                      "SELECT * FROM Customers where CustomerID = " + txtRETRIEVEid.Text  
            Dim RetrieveCmd As OleDbCommand = New OleDbCommand(RetrieveCmdQuery, DbConn)  
            Dim Dataset As New DataSet()  
            Dim dataAdapter As New OleDbDataAdapter(RetrieveCmd)  
            DbConn.Open()  
            dataAdapter.FillSchema(Dataset, SchemaType.Source, "Customers")  
            dataAdapter.Fill(Dataset, "Customers")  'get error here
     
            txtCUSTOMERid.Text = Dataset.Tables("Customers").Columns("CustomerID").ToString() 
            'extra textboxes to be filled in 
            DbConn.Close()  
     
        End Sub 

    And then after this I will have to Update and delete stuff from the database.

    Thanks in advance

    MonkeyMark
    Wednesday, October 08, 2008 5:55 AM

Answers

  •  I think the CustomerID field is of type 'text'. Can you please try the following code?

    Dim RetrieveCmdQuery As String = "SELECT * FROM Customers where CustomerID = '" + txtRETRIEVEid.Text + "'"   

    Also you might have to change the statement which fetches the customerid value like this.
    txtCUSTOMERid.Text = Dataset.Tables(0).Rows(0).Item("CustomerID") 
    Wednesday, October 08, 2008 4:43 PM
  • Did you try this code?

    txtCUSTOMERid.Text = Dataset.Tables(0).Rows(0).Item("CustomerID")  
    • Marked as answer by MonkeyMark Wednesday, October 15, 2008 3:20 AM
    Saturday, October 11, 2008 8:59 AM

All replies

  •  I think the CustomerID field is of type 'text'. Can you please try the following code?

    Dim RetrieveCmdQuery As String = "SELECT * FROM Customers where CustomerID = '" + txtRETRIEVEid.Text + "'"   

    Also you might have to change the statement which fetches the customerid value like this.
    txtCUSTOMERid.Text = Dataset.Tables(0).Rows(0).Item("CustomerID") 
    Wednesday, October 08, 2008 4:43 PM
  • Thanks for the help siva.k, it did help. But now instead of filling txtCUSTOMERid.text with the Customer ID, it just gives the column name (i.e. CustomerID) of the dataset. What am I doing wrong?
    Saturday, October 11, 2008 5:24 AM
  • Did you try this code?

    txtCUSTOMERid.Text = Dataset.Tables(0).Rows(0).Item("CustomerID")  
    • Marked as answer by MonkeyMark Wednesday, October 15, 2008 3:20 AM
    Saturday, October 11, 2008 8:59 AM
  • ohh... I'm such an idiot. Thanks for the help siva.k
    Wednesday, October 15, 2008 3:18 AM