473,669 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sqladapter Insert

I have 2 rows in a datatable

When i Adapter.Update( mytable)
i get Update requires valid update command error
When In Fact I am Inserting

SqlAdapter ad = new SqlDataAdapter( )
ad.InsertComman d=new SqlCommand();
string sInsert="Insert into mytable (field1,field2) values(@field1, @field2)
..
..ad.InsertComm and.Parameters. Add("@Field1", SqlDbType.Int, 0, "Field1");

ad.InsertComman d.Parameters.Ad d("@FileId2", SqlDbType.Int, 0, "Field2");

ad.InsertComman d.Connection=oC onn;

ad.Update(MyTab le) // crashes with requires valid update command

// if i do this

for (int rows = 0;rows<mytalble .Rows.Count;Row s++)

{

ad.InsertComman d.Parameters["@Field1"].Value=MyTable. Rows[x]["Field1"])

ad.InsertComman d.Parameters["@Field2"].Value=MyTable. Rows[x]["Field2"])

ad.InsertComman d.ExecuteNonQue ry() // Works just Fine inserts 2
Rows

}

any idea why the update requires a Update command

Thanks Dave
Jun 27 '08 #1
1 2685
I don't see in your sample where you are assigning the "sInsert" string to
the CommandText property of the InsertCommand. You also need to set the
CommandType to CommandType.Tex t.
Peter
"DaveL" <dv*****@sbcglo bal.netwrote in message
news:8H******** *******@flpi148 .ffdc.sbc.com.. .
>I have 2 rows in a datatable

When i Adapter.Update( mytable)
i get Update requires valid update command error
When In Fact I am Inserting

SqlAdapter ad = new SqlDataAdapter( )
ad.InsertComman d=new SqlCommand();
string sInsert="Insert into mytable (field1,field2)
values(@field1, @field2)
.
.ad.InsertComma nd.Parameters.A dd("@Field1", SqlDbType.Int, 0, "Field1");

ad.InsertComman d.Parameters.Ad d("@FileId2", SqlDbType.Int, 0, "Field2");

ad.InsertComman d.Connection=oC onn;

ad.Update(MyTab le) // crashes with requires valid update command

// if i do this

for (int rows = 0;rows<mytalble .Rows.Count;Row s++)

{
ad.InsertComman d.Parameters["@Field1"].Value=MyTable. Rows[x]["Field1"])
ad.InsertComman d.Parameters["@Field2"].Value=MyTable. Rows[x]["Field2"])

ad.InsertComman d.ExecuteNonQue ry() // Works just Fine inserts 2
Rows

}

any idea why the update requires a Update command

Thanks Dave

Jun 27 '08 #2

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

Similar topics

2
1995
by: Newbee Adam | last post by:
how to save textbox values to 2 tables using sqladapter I am new with this. Do I need to ADO.net? what is the simplist correct way? or can I write a query in my vb.net form insert table Machine_Count(MachName, CoinsIn) values(txtMachineName(1).Text, txtCoinsIn(1).Text)
11
409
by: Newbee Adam | last post by:
I am new to vb.net coming from vb6 (intermediate level) 1. I am trying to wrap my mind around when I would use ADO.Net and when to use sqladapter. 2.can I use sqldataadapter in web app?
14
4286
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to salvage the records from the many table and without going into detail, one of the reasons I can't do the opposite as there are records in the ONE table that I need to keep even if they don't have any child records in the MANY table. Below I created...
5
1787
by: DC Gringo | last post by:
I am having a problem reading a simple update to the database. Basically I'm testing a small change to the pubs database -- changing the price of the Busy Executive's Database Guide from 19.99 to 1997 and back. Unfortunately, it seems does reflect the change on my web form. Perhaps it's caching the data retrieved by the SQLDataAdapter? (All of my code is generated by VS.NET '03. FYI, it works fine when I test on my developer...
1
1095
by: Steve Jacklin | last post by:
How do I link a TreeView Control to an SQLAdapter?
1
3679
by: Hrvoje Voda | last post by:
How to refresh dataset and sqladapter after using store procedure? I tried to call update on sqladapter but it doesn't work. Only when I close program and call it again a change is visible. Hrcko
0
1026
by: Peter Newman | last post by:
vb.net 2003 & SQL 2005 Im expericing a lot of problems tring to configure the SQLdata Adapter using the wizard can anybody help, ive tried loads of different routes to try and get the imput form i need but all i do is go round in circles and waste my time ....... vb6 was so easy in comaprassion The wizard dectected the following problems when configuring the data adapter for SQLdataAdapter1
0
939
by: jincep | last post by:
can you tell me how to configure sql adapter in vb.net 2005. i know to configure in 2003 by right clicking sqladapter -->properties, we can. but when i right click the same properties in 2005 it shows only the properties. can u help me how it is?
2
2727
by: MikeJ | last post by:
sqldapter ms sqlserver 2005 hi i have a main database 1 databasemain 2 databaseother i have a stored proc in databaseother i get error could not find stored procedure the Proc is in Databaseother when SqlAdapter opens the connection i need to change to database other....
0
8466
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
8384
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8896
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
8590
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
8659
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6211
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4208
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...
1
2798
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
2
2035
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.