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 6 2029
"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
"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
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
.
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
.
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |