|
-
Aug 18th, 2009, 12:44 AM
#1
Thread Starter
Frenzied Member
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.
-
Aug 18th, 2009, 12:47 AM
#2
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 
-
Aug 18th, 2009, 12:47 AM
#3
Re: Data Reader giving error!!!
* 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 
-
Aug 18th, 2009, 01:24 AM
#4
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.
-
Aug 21st, 2009, 12:41 AM
#5
Thread Starter
Frenzied Member
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?
-
Aug 21st, 2009, 11:09 PM
#6
Addicted Member
Re: Data Reader giving error!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|