473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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.InsertCommand=new SqlCommand();
string sInsert="Insert into mytable (field1,field2) values(@field1,@field2)
..
..ad.InsertCommand.Parameters.Add("@Field1", SqlDbType.Int, 0, "Field1");

ad.InsertCommand.Parameters.Add("@FileId2", SqlDbType.Int, 0, "Field2");

ad.InsertCommand.Connection=oConn;

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

// if i do this

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

{

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

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

ad.InsertCommand.ExecuteNonQuery() // Works just Fine inserts 2
Rows

}

any idea why the update requires a Update command

Thanks Dave
Jun 27 '08 #1
1 2666
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.Text.
Peter
"DaveL" <dv*****@sbcglobal.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.InsertCommand=new SqlCommand();
string sInsert="Insert into mytable (field1,field2)
values(@field1,@field2)
.
.ad.InsertCommand.Parameters.Add("@Field1", SqlDbType.Int, 0, "Field1");

ad.InsertCommand.Parameters.Add("@FileId2", SqlDbType.Int, 0, "Field2");

ad.InsertCommand.Connection=oConn;

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

// if i do this

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

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

ad.InsertCommand.ExecuteNonQuery() // 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
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...
11
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
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...
5
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...
1
by: Steve Jacklin | last post by:
How do I link a TreeView Control to an SQLAdapter?
1
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
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...
0
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.