473,473 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Data Adapter

18 New Member
Dear All,

I have wriiten the following code to add a new row in author table. But it is generating an error("Update requires a valid InsertCommand when passed DataRow collection with new rows.")
Please help me on this.


Dim con As New SqlConnection("Data Source=.;Initial Catalog=student;Integrated Security=True")
Dim cmd As New SqlCommand("Select * from author", con)
con.Open()
Dim adp As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
Dim dt As DataTable
Dim dr As DataRow
adp.Fill(ds, "author")
dt = ds.Tables("author")
dr = dt.NewRow()
dr(0) = TextBox1.Text
dr(1) = TextBox2.Text
dr(2) = TextBox3.Text
dt.Rows.Add(dr)
adp.Update(ds, "author")
con.Close()

Regards

Harman
Apr 26 '08 #1
2 1940
kenobewan
4,871 Recognized Expert Specialist
Your dataadapter uses a select command, consequently it errors when you try to update. You need to supply an sql update query. HTH.
Dear All,

I have wriiten the following code to add a new row in author table. But it is generating an error("Update requires a valid InsertCommand when passed DataRow collection with new rows.")
Please help me on this.


Dim con As New SqlConnection("Data Source=.;Initial Catalog=student;Integrated Security=True")
Dim cmd As New SqlCommand("Select * from author", con)
con.Open()
Dim adp As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
Dim dt As DataTable
Dim dr As DataRow
adp.Fill(ds, "author")
dt = ds.Tables("author")
dr = dt.NewRow()
dr(0) = TextBox1.Text
dr(1) = TextBox2.Text
dr(2) = TextBox3.Text
dt.Rows.Add(dr)
adp.Update(ds, "author")
con.Close()

Regards

Harman
Apr 27 '08 #2
deric
92 New Member
You said you want to add a new row, so you need to use InsertCommand of the SqlDataAdapter.

And, your SqlCommand should be an Insert statement, not Select statement. There's a sample on the link I provided you...
Apr 28 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: pmud | last post by:
Hi, I need to display columns in a data grid based on 7 different queries. Now I have 32 questions: 1. Is it possble to have 1 single data adapter with 7 queries & 1 data set or do I need to...
5
by: Rick | last post by:
The data adapter wizard allows you to add more than one table, but that doesn't seem to work right when setting up a dataset. Some of the documentation I have read states that only one table...
4
by: William | last post by:
After much frustration I was able to update my data store via code only. Using the data adapter was the only way I was able to set up all the objects written in my code. Basically, I cheated by...
9
by: Brad | last post by:
I have written some code to manipulate data/records in a MASTER (order header) and DETAIL (order details) tables. What I have written is too extensive to post but essentially trying to: 1....
2
by: simon | last post by:
I use my functions to create adapter and fill dataSet: funkcije.createAdapter("c_CPOSkupaj", False, myParams).Fill(ds, "brezReklam") If I use this function another time to fill dataSet with...
7
by: GatorBait | last post by:
Hi all, I am having a problem with my data adapter update command. I have generated the data adapter in the IDE and then I built a dataset. The dataset can get changed in the program and I...
12
by: Randy | last post by:
Hi, Trying to pass along a table row delete to the datasource, but I'm crashing. Here is the code: Private Sub btnDeleteIngr_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
6
by: Suresh | last post by:
Hi All, I am fetching a dataset from the database under some condition. After this I create a data table. Traverse in the original dataset & add each row to created data table as it is through...
9
by: SAL | last post by:
Hello, I have a Dataset that I have table adapters in I designed using the designer (DataLayer). I have a business logic layer that immulates the DataLayer which may/may not have additional logic...
6
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1)...
0
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...
0
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,...
1
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...
0
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...
0
agi2029
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,...
0
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...
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.