473,396 Members | 2,013 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,396 software developers and data experts.

Data is not inserting inn database

Hi ,
I am trying to insert records into database. I am trying
to write the following code.
On button1 click event i am inserting five records and
after that i am calling the update method of dataadapter
to update the records in database.
Records are inserting but all the five records have the
same value and that too of that last ones..
More over i tried to use the acceptchanges methods for
datatable and dataset but of no use
ihave used the following code

Dim da As New OleDb.OleDbDataAdapter("select * from
test", "Provider=SQLOLEDB;Data Source=192.168.16.4;Initial
Catalog=Northwind;user id=sa;password=;")
Dim myConnection As New OleDb.OleDbConnection
("Provider=SQLOLEDB;Data Source=192.168.16.4;Initial
Catalog=Northwind;user id=sa;password=;")
Dim dt As DataTable
Dim dr As DataRow
Dim ds As New DataSet()

Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
da.Fill(ds, "test")
End Sub

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
dt = ds.Tables("test")
da.InsertCommand = New OleDb.OleDbCommand("insert
test values('" + TextBox1.Text + "','" + TextBox2.Text
+ "')", myConnection)
Dim i As Integer
dr = dt.NewRow()
dr("name") = TextBox1.Text
dr("address") = TextBox2.Text

dt.Rows.Add(dr)
MsgBox(dt.Rows.Count())
End Sub

Private Sub Button2_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
Try

da.Update(ds, "test")
MsgBox("Record saved")
Catch er As Exception
MsgBox(er.ToString)
End Try
End Sub
Nov 20 '05 #1
6 2025
Cor
"Hi Pushpendra Vats

I deleted some things and added some things, that commandbuilder is not the
nicest however that insert command you was using also not.

Give it a try?

It is just changed in the text so watch typos or other errors.

Cor
"> Dim da As New OleDb.OleDbDataAdapter("select * from
test", "Provider=SQLOLEDB;Data Source=192.168.16.4;Initial
Catalog=Northwind;user id=sa;password=;")
Dim myConnection As New OleDb.OleDbConnection
("Provider=SQLOLEDB;Data Source=192.168.16.4;Initial
Catalog=Northwind;user id=sa;password=;") Dim ds As New DataSet() Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
da.Fill(ds, "test")
End Sub
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
dt = ds.Tables("test")
dim dr as datarow = dt.NewRow()
dr("name") = TextBox1.Text
dr("address") = TextBox2.Text
dt.Rows.Add(dr)
MsgBox(dt.Rows.Count())
End Sub
Private Sub Button2_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
Try dim cmb as new OleDb.OleDbcommandbuilder(da) da.Update(ds, "test")
MsgBox("Record saved")
Catch er As Exception
MsgBox(er.ToString)
End Try
End Sub

Nov 20 '05 #2
Cor
"Hi Pushpendra Vats

I deleted some things and added some things, that commandbuilder is not the
nicest however that insert command you was using also not.

Give it a try?

It is just changed in the text so watch typos or other errors.

Cor
"> Dim da As New OleDb.OleDbDataAdapter("select * from
test", "Provider=SQLOLEDB;Data Source=192.168.16.4;Initial
Catalog=Northwind;user id=sa;password=;")
Dim myConnection As New OleDb.OleDbConnection
("Provider=SQLOLEDB;Data Source=192.168.16.4;Initial
Catalog=Northwind;user id=sa;password=;") Dim ds As New DataSet() Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
da.Fill(ds, "test")
End Sub
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
dt = ds.Tables("test")
dim dr as datarow = dt.NewRow()
dr("name") = TextBox1.Text
dr("address") = TextBox2.Text
dt.Rows.Add(dr)
MsgBox(dt.Rows.Count())
End Sub
Private Sub Button2_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
Try dim cmb as new OleDb.OleDbcommandbuilder(da) da.Update(ds, "test")
MsgBox("Record saved")
Catch er As Exception
MsgBox(er.ToString)
End Try
End Sub

Nov 20 '05 #3
Dear Cor,
Thanks a lot fro the solution but i really could not
understand why the same is not working with the
insertcommand.

One more thing if i use the acceptchanges method with
datatablenad dataset still it was not working....

Thanks a lot....again....

pushpendra
-----Original Message-----
"Hi Pushpendra Vats

I deleted some things and added some things, that commandbuilder is not thenicest however that insert command you was using also not.

Give it a try?

It is just changed in the text so watch typos or other errors.
Cor
"> Dim da As New OleDb.OleDbDataAdapter("select * from
test", "Provider=SQLOLEDB;Data Source=192.168.16.4;Initial Catalog=Northwind;user id=sa;password=;")
Dim myConnection As New OleDb.OleDbConnection
("Provider=SQLOLEDB;Data Source=192.168.16.4;Initial
Catalog=Northwind;user id=sa;password=;")

Dim ds As New DataSet()
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
da.Fill(ds, "test")
End Sub
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
dt = ds.Tables("test")
dim dr as datarow = dt.NewRow()
dr("name") = TextBox1.Text
dr("address") = TextBox2.Text
dt.Rows.Add(dr)
MsgBox(dt.Rows.Count())
End Sub
Private Sub Button2_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
Try

dim cmb as new OleDb.OleDbcommandbuilder(da)
da.Update(ds, "test")
MsgBox("Record saved")
Catch er As Exception
MsgBox(er.ToString)
End Try
End Sub

.

Nov 20 '05 #4
Dear Cor,
Thanks a lot fro the solution but i really could not
understand why the same is not working with the
insertcommand.

One more thing if i use the acceptchanges method with
datatablenad dataset still it was not working....

Thanks a lot....again....

pushpendra
-----Original Message-----
"Hi Pushpendra Vats

I deleted some things and added some things, that commandbuilder is not thenicest however that insert command you was using also not.

Give it a try?

It is just changed in the text so watch typos or other errors.
Cor
"> Dim da As New OleDb.OleDbDataAdapter("select * from
test", "Provider=SQLOLEDB;Data Source=192.168.16.4;Initial Catalog=Northwind;user id=sa;password=;")
Dim myConnection As New OleDb.OleDbConnection
("Provider=SQLOLEDB;Data Source=192.168.16.4;Initial
Catalog=Northwind;user id=sa;password=;")

Dim ds As New DataSet()
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
da.Fill(ds, "test")
End Sub
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
dt = ds.Tables("test")
dim dr as datarow = dt.NewRow()
dr("name") = TextBox1.Text
dr("address") = TextBox2.Text
dt.Rows.Add(dr)
MsgBox(dt.Rows.Count())
End Sub
Private Sub Button2_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
Try

dim cmb as new OleDb.OleDbcommandbuilder(da)
da.Update(ds, "test")
MsgBox("Record saved")
Catch er As Exception
MsgBox(er.ToString)
End Try
End Sub

.

Nov 20 '05 #5
Hi Pushpendra,

Maybe the insert does work also, however why do more work than needed.

The acceptchanges is to prevent updating.

It stands for Accept the changes as if you did the updating.

Cor
Nov 20 '05 #6
Hi Pushpendra,

Maybe the insert does work also, however why do more work than needed.

The acceptchanges is to prevent updating.

It stands for Accept the changes as if you did the updating.

Cor
Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jared Evans | last post by:
I developed a console application that will continually check a message queue to watch for any incoming data that needs to be inserted into MS SQL database. What would be a low-cost method I...
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...
0
by: Pushpendra Vats | last post by:
Hi , I am trying to insert records into database. I am trying to write the following code. On button1 click event i am inserting five records and after that i am calling the update method of...
5
by: hfk0 | last post by:
Hi, I'm new to ASP.net, SQL Server and visual studio.net, and I'm having problem inserting and storing data from a web form to a SQL database. I created a simple ASP.NET web form, a simple SQL...
0
by: pd123 | last post by:
I'm new to C# and .net and I'm trying to create a form that will register users in a sql server database. I have the following code but when I run the code I get an error " The name 'Peter' is...
2
by: Etayki | last post by:
Hi! I am trying to insert data into a MS SQL Database from a Console Application written in VB.net I have already created the table in the database and I am able to read values. When I insert a...
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...
18
by: boss1 | last post by:
Hi all, i m having a problem with inserting data in oracle db. When i use form action =(call self page) then data is inserting properly.But problem with when using form...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.