By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,827 Members | 2,195 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,827 IT Pros & Developers. It's quick & easy.

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

P: n/a
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) "

Jan 3 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi aniket_sp,

What is the value of rno when you arrive in FillData ?

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
ci**************@msn.com www.cindywinegarden.com
"aniket_sp" <pi***********@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
rno = 0
call filldata()

filldata function consists of the following

With DataSet11.Tables("Table1").Rows(rno) ..... 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) "

Jan 3 '06 #2

P: n/a
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

Jan 3 '06 #3

P: n/a
Is that the entire contents of filldata, that snippet you posted?

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

"aniket_sp" <pi***********@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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) "

Jan 3 '06 #4

P: n/a
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?

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
ci**************@msn.com www.cindywinegarden.com
"aniket_sp" <pi***********@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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

Jan 4 '06 #5

P: n/a

Cindy Winegarden wrote:
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?

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
ci**************@msn.com www.cindywinegarden.com
"aniket_sp" <pi***********@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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

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.

Jan 4 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.