473,594 Members | 2,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.OleDbData Adapter("select * from
test", "Provider=SQLOL EDB;Data Source=192.168. 16.4;Initial
Catalog=Northwi nd;user id=sa;password= ;")
Dim myConnection As New OleDb.OleDbConn ection
("Provider=SQLO LEDB;Data Source=192.168. 16.4;Initial
Catalog=Northwi nd;user id=sa;password= ;")
Dim dt As DataTable
Dim dr As DataRow
Dim ds As New DataSet()

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

Private Sub Button1_Click(B yVal sender As
System.Object, ByVal e As System.EventArg s) Handles
Button1.Click
dt = ds.Tables("test ")
da.InsertComman d = New OleDb.OleDbComm and("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(B yVal sender As
System.Object, ByVal e As System.EventArg s) Handles
Button2.Click
Try

da.Update(ds, "test")
MsgBox("Record saved")
Catch er As Exception
MsgBox(er.ToStr ing)
End Try
End Sub
Nov 20 '05 #1
6 2045
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.OleDbData Adapter("select * from
test", "Provider=SQLOL EDB;Data Source=192.168. 16.4;Initial
Catalog=Northwi nd;user id=sa;password= ;")
Dim myConnection As New OleDb.OleDbConn ection
("Provider=SQLO LEDB;Data Source=192.168. 16.4;Initial
Catalog=Northwi nd;user id=sa;password= ;") Dim ds As New DataSet() Private Sub Form1_Load(ByVa l sender As System.Object,
ByVal e As System.EventArg s) Handles MyBase.Load
da.Fill(ds, "test")
End Sub
Private Sub Button1_Click(B yVal sender As
System.Object, ByVal e As System.EventArg s) 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(B yVal sender As
System.Object, ByVal e As System.EventArg s) Handles
Button2.Click
Try dim cmb as new OleDb.OleDbcomm andbuilder(da) da.Update(ds, "test")
MsgBox("Record saved")
Catch er As Exception
MsgBox(er.ToStr ing)
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.OleDbData Adapter("select * from
test", "Provider=SQLOL EDB;Data Source=192.168. 16.4;Initial
Catalog=Northwi nd;user id=sa;password= ;")
Dim myConnection As New OleDb.OleDbConn ection
("Provider=SQLO LEDB;Data Source=192.168. 16.4;Initial
Catalog=Northwi nd;user id=sa;password= ;") Dim ds As New DataSet() Private Sub Form1_Load(ByVa l sender As System.Object,
ByVal e As System.EventArg s) Handles MyBase.Load
da.Fill(ds, "test")
End Sub
Private Sub Button1_Click(B yVal sender As
System.Object, ByVal e As System.EventArg s) 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(B yVal sender As
System.Object, ByVal e As System.EventArg s) Handles
Button2.Click
Try dim cmb as new OleDb.OleDbcomm andbuilder(da) da.Update(ds, "test")
MsgBox("Record saved")
Catch er As Exception
MsgBox(er.ToStr ing)
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.OleDbData Adapter("select * from
test", "Provider=SQLOL EDB;Data Source=192.168. 16.4;Initial Catalog=Northwi nd;user id=sa;password= ;")
Dim myConnection As New OleDb.OleDbConn ection
("Provider=SQLO LEDB;Data Source=192.168. 16.4;Initial
Catalog=Northwi nd;user id=sa;password= ;")

Dim ds As New DataSet()
Private Sub Form1_Load(ByVa l sender As System.Object,
ByVal e As System.EventArg s) Handles MyBase.Load
da.Fill(ds, "test")
End Sub
Private Sub Button1_Click(B yVal sender As
System.Object, ByVal e As System.EventArg s) 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(B yVal sender As
System.Object, ByVal e As System.EventArg s) Handles
Button2.Click
Try

dim cmb as new OleDb.OleDbcomm andbuilder(da)
da.Update(ds, "test")
MsgBox("Record saved")
Catch er As Exception
MsgBox(er.ToStr ing)
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.OleDbData Adapter("select * from
test", "Provider=SQLOL EDB;Data Source=192.168. 16.4;Initial Catalog=Northwi nd;user id=sa;password= ;")
Dim myConnection As New OleDb.OleDbConn ection
("Provider=SQLO LEDB;Data Source=192.168. 16.4;Initial
Catalog=Northwi nd;user id=sa;password= ;")

Dim ds As New DataSet()
Private Sub Form1_Load(ByVa l sender As System.Object,
ByVal e As System.EventArg s) Handles MyBase.Load
da.Fill(ds, "test")
End Sub
Private Sub Button1_Click(B yVal sender As
System.Object, ByVal e As System.EventArg s) 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(B yVal sender As
System.Object, ByVal e As System.EventArg s) Handles
Button2.Click
Try

dim cmb as new OleDb.OleDbcomm andbuilder(da)
da.Update(ds, "test")
MsgBox("Record saved")
Catch er As Exception
MsgBox(er.ToStr ing)
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
3422
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 could use inside this console application to make sure the MS SQL database is operational before I perform the insert?
2
2204
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 access the database layer. However, the code works in a pretty cumbersome and ungeneric way. Basically every query, update, and insert has its own function. So you see a lot of functions like webService.InsertCustomer(name, age, phone); or...
0
766
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 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
5
2191
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 database, a database connection (using the SQlDataSource Web Control from the Toolbox), and created the following stored procedure in Visual Studio.Net 2005:
0
2996
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 not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted. Where Peter is the value entered in the textbox for firstname (fnameTBox) I'm sure the problem is something obvious but I...
2
4851
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 value using the Table Adapter's Query "InsertQuery", I am able to see that the data was inserted during runtime upon reading back the value that was inserted. However, when the program is over I look at the database and see that the data row has...
6
8152
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 server mobile ce database. Until recently I was synching everything thru a com port serial cable. The devices would connect to the computer thru activesync and are able to acquire an internet connection. The sync for the program occurs thru a website...
18
2766
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 action=(Another_page).data is not insering into database.For ur kind infromation i m using oracle db and php for my application. sample code: <form action="welcome.php" method="post"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" />
2
3070
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 section: Discography --------------------- DiscID
0
7947
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8255
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8010
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6665
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5413
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3868
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3903
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1486
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.