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 1909
"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...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...
| |