bind textbox to table

tprsan

Member
Joined
Feb 17, 2010
Messages
8
Programming Experience
3-5
hi developers.......

i want to read the data from the table to textbo......below is my code.....when i try to run it it shows the error.........plz help me....

following are error.....

IndexOutOfRangeException was Unhandled

Make sure that the max row on a list is is less than list size...

below is the code

Imports System
Imports System.Configuration
Imports System.Data.OleDb
Imports System.Data
Imports System.Data.SqlClient
Imports System.ParamArrayAttribute
Imports System.Data.ParameterDirection
Imports System.Web
Imports System.EventArgs
Imports System.Windows.Forms.ComboBox
Imports System.Data.DataRowView
Public Class amountdetails
Dim cong As New SqlConnection
Dim cmdg As New SqlCommand
Dim adpg As New SqlDataAdapter("SELECT * FROM disstock", cong)
Dim qqg As New DataTable


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
cong.ConnectionString = "Data Source=QUANO-462F6EB27;Initial Catalog=qraghul;Integrated Security=True"
cmdg = New SqlCommand("SELECT totalamount FROM disstock where id='" + TextBox1.Text + "'", cong)

cong.Open()

Dim myDataReader As SqlDataReader = cmdg.ExecuteReader()
If myDataReader.HasRows Then

Me.TextBox4.Text = myDataReader("totalamount") Else
Me.TextBox4.Text = "No Records"
End If
cong.Close()
End Sub
End Class

i am getting error on the line which is bolded.....

my table disstock contains three fields with more than 10 values.....
plz .....repllyyyyyyyyyyy
very urgent
 
You have to call Read on the DataReader in order to advance to the first, and then subsequent, record.

On another note, you shouldn't be using a DataReader at all. If you want a single value from the database then you should be calling ExecuteScalar.
 
Back
Top