Insert data into SQL Server using Dataadapter

Hello,

Pls help me out... What's wrong with this code. Its executing without error. But no changes in SQL database.
Dim connstring As String = "server=nt1;uid=s;pwd=r;database=rates"
cnPrintegra = New SqlConnection()
dsPrintegra = New DataSet()
cnPrintegra.ConnectionString = connstring
cnPrintegra.Open()
cmdUsers = New SqlDataAdapter("select * from R608367953", cnPrintegra)
cmdUsers.Fill(dsPrintegra, "R608367953")

Dim cRow As DataRow = dsPrintegra.Tables(0).NewRow()
cRow(0) = "99992"
cRow(1) = "23423"
dsPrintegra.Tables(0).Rows.Add(cRow)
dsPrintegra.AcceptChanges()
cmdUsers.Update(dsPrintegra, "R608367953")
cnPrintegra.Close()
Thanks in advance
Ilango

Ilango
0
ilangoaspnet
11/25/2002 2:07:43 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

5 Replies
670 Views

Similar Articles

[PageSpeed] 26

The above will create a SqlDataAdapter with a Select command, but without an insert command.  If you break the code and look at the values of cmdUsers.InsertCommand and cmdUsers.SelectCommand you will see the problem.  As there is no InsertCommand, nothing will be inserted.

To automatically generate the InsertCommand, use:
Dim objBuildIt As SqlCommandBuilder = New SqlCommandBuilder(objDacmdUsers).
This looks at the SelectCommand and determines the appropriate syntax for the Insert, Delete and Update commands. Note that it works in this case because you are dealing with a simple table, but in more complex cases you have to generate the code yourself.
Simon Kempson

Consultant based in London, UK.

www.gate99.com
0
gate
11/26/2002 9:53:52 AM
I should have mentioned that when you use SqlCommandBuilder, the InsertCommand won't be visible using cmdUsers.InsertCommand as it is created on the fly when Row_Updated fires.

However, you can check it by putting the following into your code and checking the avlue of strTmp:
Dim strTmp as string = objBuildIt.GetInsertCommand.CommandText

Simon Kempson

Consultant based in London, UK.

www.gate99.com
0
gate
11/26/2002 10:15:58 AM
Gete 99,

Thanks for your reply. Also, how do i find a row in dataset.

Ilango
0
ilangoaspnet
11/26/2002 5:03:34 PM
Here's my question....

When the "cmdUsers.Fill(dsPrintegra, "R608367953")" statement is executed, it goes out to get data from the SQL table in question.
Is it possible to insert a new row into the table in question without doing the "cmdUsers.Fill(dsPrintegra, "R608367953")" statement.
Reasoning is that I don't want to load a huge table into memory when I know all I have to do is insert a new row!
Thanx,
SilverSting.
0
silversting
9/16/2003 11:26:33 PM
This question belongs in a new thread.

Also, this forum is to discuss SQL Server and MSDE queries, etc. ADO.NET questions should go in the Data Access forum.
Terri
Terri Morton
Engagement Manager, Neudesic

How to ask a question

0
tmorton
9/17/2003 1:36:08 PM
Reply:

Web resources about - Insert data into SQL Server using Dataadapter - asp.net.sql-datasource

Microsoft Data Access Components - Wikipedia, the free encyclopedia
This article has an unclear citation style . The references used may be made clearer with a different or consistent style of citation , footnoting ...

BlueVision, LLC - .NET Tips and Tricks
Note: Some tips might become outdated as new versions of the associated products are released. Debugging the OnStart method of a Windows Service ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

DotNetNuke – Data Access Layer Alternative
-*+Now that I’ve explained the standard way of creating a Data Access Layer (DAL) for DotNetNuke, we can address the alternative method of providing ...

MSDN Magazine December 2001
The Windows XP kernel includes a number of improvements over Windows 2000 that promote better scalability and overall performance. This article ...

Visionpace :: Software Development in pace with your vision
Software development, coaching and training using Agile methodology and Microsoft technologies

accounting software using visual basic and c#
developing accounting software using visual basic and C#

Latest Updates
Latest Updates - Free source code and tutorials for Software developers and Architects.; Updated: 15 Feb 2013

Latest Updates
Latest Updates - Free source code and tutorials for Software developers and Architects.; Updated: 15 Feb 2013

Resources last updated: 11/21/2015 4:31:20 AM