Results 1 to 6 of 6

Thread: Data Reader giving error!!!

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2009
    Posts
    1,103

    Unhappy Data Reader giving error!!!

    I have a show button.The user will select a data from the dropdown list of the combo and on clicking the show button the corresponding data will be fetched from the database and will be shown in the corresponding fields.
    So I did this code:
    Code:
     Private Sub Show_Btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Show_Btn.Click
            Using connection As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=BankAccount.mdb")
                connection.Open()
                Dim command As New OleDbCommand("Select * from BankAccount", connection)
                Dim reader As OleDbDataReader = command.ExecuteReader()
                While reader.Read()
                    ComboBox1.Items.Add(reader.GetString("BankName"))
                    ComboBox2.Items.Add(reader.GetString("AccountNo"))
                    ComboBox3.Items.Add(reader.GetString("BankName"))
                    ComboBox4.Items.Add(reader.GetString("AccountNo"))
                End While
                reader.Close()
            End Using
        End Sub
    i get this error:
    Code:
    Conversion from string "BankName" to type 'Integer' is not valid.

  2. #2
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Data Reader giving error!!!

    BankName is a String,
    you can't save it as Integer
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  3. #3
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Data Reader giving error!!!

    Double Post :B
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Data Reader giving error!!!

    You should pay attention to what Intellisense tells you. As you were typing that code Intellisense would have told you that GetString accepts only an Integer argument. Failing that, read the documentation. If you try to call GetString and it doesn't work then go to the documentation and read about GetString and make sure you're using it properly. You can fix problems for yourself if you pay attention to the information that's available to you.

    http://msdn.microsoft.com/en-us/libr...8VS.80%29.aspx

    If you read that it is obvious that you can't pass a column name to GetString. Always read the documentation first.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2009
    Posts
    1,103

    Re: Data Reader giving error!!!

    Code:
    con.Open()
                cmd = New OleDbCommand("select * from MLoan where LAcNo=@loanacno", con)
                cmd.Parameters.AddWithValue("@loanacno", ComboBox1.Text)
                dr = cmd.ExecuteReader
                While dr.Read()
                    ComboBox1.Text = dr(0)
                    ComboBox2.Text = dr(1)
                    ComboBox3.Text = dr(2)
                    ComboBox4.Text = dr(6)
                    ComboBox5.Text = dr(7)
                    ComboBox8.Text = dr(10)
                    ComboBox7.Text = dr(9)
                    ComboBox9.Text = dr(11)
                    TextBox1.Text = dr(3)
                    TextBox2.Text = dr(4)
                    TextBox3.Text = dr(5)
                    TextBox4.Text = dr(8)
                    TextBox5.Text = dr(12)
                End While
    I did this code for using the datareader.
    Is this the correct way to use the datareader?

  6. #6
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Re: Data Reader giving error!!!

    is it solved?????

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width