473,408 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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

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
5 2214
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
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
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
12
by: VMI | last post by:
For some reason, the process of retrieving data (about 20 records) from an Access table that has 400K records to a dataTable is taking over 3 mins. to complete. Below is my code to connect to the...
4
by: Newbie | last post by:
hello! i'm new to sql server and having some problem getting the primary key or index (Reference column). opening up the design table, the primary key or index column has an identity seed number...
2
by: headware | last post by:
I'm relatively new to ASP.NET and ADO.NET, but I have a basic design question regarding the use of web services and APS.NET applications. Right now we have an application that uses web services to...
2
by: Parveen | last post by:
I have a data grid that's bound to a table in my dataset. After inserting a new row into the grid and populating it with data, I go to save my changes. My data adapter update command returns an...
12
by: Simon | last post by:
Hi all, I'm having a baffling problem with a windows service that I'm working on. Basically, I am using a typed dataset to insert a large number of rows into an SQL Server 2005 database. But...
3
by: Fred Chateau | last post by:
Any obvious reason here why data is not being loaded into the database? SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommand); SqlCommandBuilder commandBuilder = new...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
3
by: Surya | last post by:
Dear All, I have problem on inserting a record to database..Although it looked easy.. i have caught up with following issue .. please go ahead and help me to find solution I Need to insert...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.