problem with data adapter and data set while inserting and retrieving data

A

aniket_sp

i am using a data adapter and a dataset for filling and retrieving data
into .mdb database.
following is the code.....

for the form load event
Dim dc(0) As DataColumn
Try
If OleDbConnection1.State = ConnectionState.Closed Then
OleDbConnection1.Open()
Else
MsgBox("connection can not be established")
End If
DA.Fill(DataSet11, "Table1")
cmd = New OleDbCommandBuilder(DA)
dc(0) = DataSet11.Tables("Table1").Columns("EmpID")
DataSet11.Tables("Table1").PrimaryKey = dc
Catch ex As Exception
MsgBox(ex.Message)
End Try
Delete.Enabled = False
End Sub

for inserting values into the DB

Private Sub Insert_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Insert.Click
Dim dr As DataRow
dr = DataSet11.Tables("Table1").NewRow
dr.Item(0) = Val(TB1.Text)
dr.Item(1) = TB2.Text
dr.Item(2) = TB3.Text
dr.Item(3) = Val(TB4.Text)
dr.Item(4) = TB5.Text
DataSet11.Tables("Table1").Rows.Add(dr)
DA.Update(DataSet11, "Table1")
MsgBox("data is saved")
rno = 0
call filldata()

filldata function consists of the following

With DataSet11.Tables("Table1").Rows(rno)
TB1.Text = Trim(.Item(0))
TB2.Text = Trim(.Item(1))
TB3.Text = Trim(.Item(2))
TB5.Text = Trim(.Item(4))
End With

the error it gives is " there is no row at
0........system.nullreference...........i checked the connection and
its working fine and also the database is getting accessed........the
error is occuring at the line " With
DataSet11.Tables("Table1").Rows(rno) "
 
A

aniket_sp

i initialised it to 0.......it didnt work coz the error mesage is
"there is no row present at position 0" then i intialised to same other
value.....now the message "there is no row present at position (the
number i initialsed)".........and even if i do not initialise it still
the problem persists
 
M

Marina

Is that the entire contents of filldata, that snippet you posted?

Also, right before you call filldata, what is
DataSet11.Tables("Table1").Rows.Count?
 
C

Cindy Winegarden

Let me get this straight. You enter values into the text boxes on your form
and then click your Insert button. Clicking the Insert button adds a row and
populates its values from the boxes on your form. Presumably each time you
click the button you add another row to your dataset, and each of these rows
will have a new row number. Right so far?

After you add your row and populate its values you call FillData.

I'm really not sure what FillData is supposed to do. You've just set values
in your row from the boxes on your form and in FillData it looks like you're
setting the values for the boxes on the form from the values in the row.
Wouldn't the boxes already have those values, or are you perhaps trying to
set the boxes back to some sort of default value from some row that's always
the same?

How does FillData know what the value of rno is supposed to be unless you
pass it in as a parameter?
 
A

aniket_sp

Cindy said:
Let me get this straight. You enter values into the text boxes on your form
and then click your Insert button. Clicking the Insert button adds a row and
populates its values from the boxes on your form. Presumably each time you
click the button you add another row to your dataset, and each of these rows
will have a new row number. Right so far?

After you add your row and populate its values you call FillData.

I'm really not sure what FillData is supposed to do. You've just set values
in your row from the boxes on your form and in FillData it looks like you're
setting the values for the boxes on the form from the values in the row.
Wouldn't the boxes already have those values, or are you perhaps trying to
set the boxes back to some sort of default value from some row that's always
the same?

How does FillData know what the value of rno is supposed to be unless you
pass it in as a parameter?


DataSet11.Tables("Table1").Rows.Count??
its not .count but its (rno)...rno is the row no......and it is being
passed as a parameter after initialsing it to some value......when
filldata is called it is supposed to fill the data into the data
set....intially text boxes are bound to the respective locations of the
..mdb database........then a call to filldata is placed after which
updations to the database from the dataset named DATASET 11.......the
error is related to sytem.data.dll......but i dont find a clue to it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top