The following code:
Try
da.Update(ds.Ta bles(dg1Name))
Catch ex As Exception
Console.WriteLi ne(ex.ToString)
MessageBox.Show (ex.ToString)
End Try
causes this error:
System.InvalidO perationExcepti on: Update requires a valid UpdateCommand when
passed DataRow collection with modified rows.
at System.Data.Com mon.DbDataAdapt er.Update(DataR ow[] dataRows,
DataTableMappin g tableMapping)
at System.Data.Com mon.DbDataAdapt er.Update(DataT able dataTable)
at comments.Form1. Button1_Click(O bject sender, EventArgs e) in
G:\Shared\VBSha re\dotnet\Kevin \comments\Form1 .vb:line 161
The code is behiend a button on the form called Update. If I change the data
in the grid I get the error when I press the update button. Any advice will
be much appreciated.
Kevin 10 1483
Kevin,
How did you create your update command?
You have as far as I know 3 possibilities
- by hand yourself
- using an AdapterWizard
- using an commandbuilder.
Now your error can be everything.
Cor
Cor,
I did not create an update command, I used the following code to fill the
grid, changed one of the records and thought that the dataset and data
adaptor took care of the rest?
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim commands As String = Microsoft.Visua lBasic.Command
Dim strDatabase, strSQL As String
strDatabase = Mid(commands, 1, 7)
gstrCustomer = Mid(commands, 9, 12)
gstrOrder = Mid(commands, 22, 8)
gstrOrdType = Mid(commands, 31, 1)
Call connectSQL(strD atabase)
'fill the grid
strSQL = "select '" & "Y" & "' as Selected, seqNo, comment from
sql_oe_comments where custNo = '" & gstrCustomer & "'"
cb = New SqlCommandBuild er(da)
ds = New DataSet()
da = New SqlDataAdapter( strSQL, sqlConn)
da.Fill(ds, dg1Name)
With DG1 'this is the datagrid on the form
.DataSource = ds.Tables(dg1Na me)
.AllowSorting = True
.AlternatingBac kColor = System.Drawing. Color.Bisque
End With
'format the grid
Call formatGridDG1()
End Sub
"Cor Ligthert" wrote: Kevin,
How did you create your update command?
You have as far as I know 3 possibilities - by hand yourself - using an AdapterWizard - using an commandbuilder.
Now your error can be everything.
Cor
Kevin,
There is a commandbuilder in the code you showed and that I asked for.
By the way, are you sure that this works da.Fill(ds, dg1Name)
And not just this
da.Fill(ds)
Let us assume that you have a button on your form on what you click and in
that click event you set this code
BindingContext( ds.Tables(0)).E ndCurrentEdit()
Try
da.Update(ds.Ta bles(0))
Catch ex As Exception
Console.WriteLi ne(ex.ToString)
MessageBox.Show (ex.ToString)
End Try
Than it is bad code, however it will probably work and when you are a newbie
is that one of the first things that is important.
I hope this helps
Cor.
Cor,
Thanks for the reply. dg1Name is a public constant. I found (by trial and
error) that if I don't use it in these three places: da.Fill(ds, dg1Name),
..DataSource = ds.Tables(dg1Na me), ts.MappingName = dg1Name I get an error on
this line of code: Me.DG1.TableSty les(0).GridColu mnStyles(2).Hea derText =
"COMMENTS"
I took out the grid foramtting and used ds.fill(0) as you suggested adding
the binding code and received the same error originally reported about the
command builder? If there is a better way to do this please let me know, the
book I have suggests that it should work, obviously I must be doing something
wrong.
Thanks,
Kevin Kevin,
There is a commandbuilder in the code you showed and that I asked for.
By the way, are you sure that this works da.Fill(ds, dg1Name) And not just this da.Fill(ds)
Let us assume that you have a button on your form on what you click and in that click event you set this code
BindingContext( ds.Tables(0)).E ndCurrentEdit() Try da.Update(ds.Ta bles(0)) Catch ex As Exception Console.WriteLi ne(ex.ToString) MessageBox.Show (ex.ToString) End Try
Than it is bad code, however it will probably work and when you are a newbie is that one of the first things that is important.
I hope this helps
Cor.
Kevin,
Your select statement looks not simple for me to translate for the
commandbuilder, can you not first try it with a simple one as
"Select * from MyTable"
Cor
Cor,
I tried a simple statement and got the error: "update requires a valid
update command..." I have a command builder object but have not structured
any update statements for it? Is there a repository of code samples that show
how this is done? The book I have isn't clear about how the update works.
Thanks,
Kevin
"Cor Ligthert" wrote: Kevin,
Your select statement looks not simple for me to translate for the commandbuilder, can you not first try it with a simple one as
"Select * from MyTable"
Cor
Kevin,
Can you show us a part of your code as you have it now, the commandbuilder
needs in most cases like yours, nothing extra than that it is called.
Cor
Cor,
Here's the code I'm currently using to fill the grid:
Public ds As New Data.DataSet()
Public da As SqlClient.SqlDa taAdapter
Public cmd As SqlClient.SqlCo mmandBuilder()
Private Sub Form Load
strConn = "Initial Catalog=data_05 ;Data Source=kevin;Us er
ID=test;passwor d=test;"
strSQL = "select * from sql_oe_comments "
da = New SqlClient.SqlDa taAdapter(strSQ L, strConn)
da.Fill(ds)
dg1.DataSource = ds.Tables(0)
End Sub
Then I modify data in the grid and click the update button which has the
following code:
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Try
dg1.Update()
'da.update(ds.t ables(0))
Catch ex As Exception
MessageBox.Show (ex.ToString)
End Try
End Sub
With this code I do not get an error when I press the button but the sql
data does not change in the database? If I uncomment the da.update... then I
get an error that a valid update command is required?
"Cor Ligthert" wrote: Kevin,
Can you show us a part of your code as you have it now, the commandbuilder needs in most cases like yours, nothing extra than that it is called.
Cor
Kevin,
I am glad I asked it to show some code, you don't use a commandbuilder, you
only create a placeholder for it. Can you try the changes I wrote in line. I
did it in this message so watch typos. Public ds As New Data.DataSet() Public da As SqlClient.SqlDa taAdapter
............ Private Sub Form Load strConn = "Initial Catalog=data_05 ;Data Source=kevin;Us er ID=test;passwor d=test;" strSQL = "select * from sql_oe_comments " da = New SqlClient.SqlDa taAdapter(strSQ L, strConn) da.Fill(ds)
dim cmd as new sqlClient.SqlCo mmandBuilder(da )
dg1.DataSource = ds.Tables(0).de faultview
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
Me.BindingConte xt(dg1.DataSour ce).EndCurrentE dit()
Try
da.update(ds.ta bles(0)) Catch ex As Exception MessageBox.Show (ex.ToString) End Try
End Sub
I hope this helps,
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: pmud |
last post by:
Hi,
I have 4 columns in my sql database table. I added a data adapter , data set
& a data grid to view this information. But the data grid is displaying those
4 columns TWICE , i.e in the data grid i see 8 columns.
In case this is useful, the primary key is Serial no. which is an identity
....i.e everytime a row is added to the database, it increments by1. Also,
when i configured the data adapter, it couldnt Generate the UPDATE &...
|
by: jijo kuruvila |
last post by:
actually my code looks like this
private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.Columns.Visible=true;
DataGrid1.Columns.Visible=true;
TextBox t1=new TextBox();
TextBox t6=new TextBox();
TextBox t7=new TextBox();
|
by: Tejpal Garhwal |
last post by:
I have datagrid filled with some data rows. At the run time i want know how
many total rows are there in the data grid ?
Any idea ? Any Suggestions ?
Thanks in advance
Tej
|
by: nyt |
last post by:
I have a problem of number and text field.
I got the database file(mdb) that contains many combo boxes used and
its list values are created by "value list"
For eg field
Field name= 'furniture' , data type='Number' ,Display Control='Combo
Box', RowSource Type = 'Value List' and
Row Source = ' 0;"chair";1;"Table";2;"Bed" '
Therefore, in data sheet view of table, if we select (1 : Table ) ,
|
by: Vijendra Malhotra |
last post by:
What is the fastest way to refresh contents in a data grid. I would
like to populate a grid based on message from a EMS queue with a
frequency of about 100 messages per second.
what is the best way to do this?
| |
by: marty |
last post by:
I did some searchs, but can't find the answer to my problems.
I have a editable DataGrid.
I do an update of one of the rows.
Postback "OnUpdateCommand"
Call Oracle proc to do that actual update, which in turn creates a new
row (effective dating).
Call BindGrid which retrieves the rows and binds the data to the grid
again.
|
by: John J. Hughes II |
last post by:
I have a DataGridView with a TextBoxColumn. I setting the data source to a
List<stringvalue in a static class. The list is filled from a background
thread. So far all is fine and it works great, at least on my system.
The reason I am doing this is some customers are pulling from VPN
connections which are slow. This allows the list of rows in the data grid
to appear a little quicker while the list which are not used as soon load in...
|
by: Anil Gupte |
last post by:
After reading a tutorial and fiddling, I finally got this to work. I can
now put two tables created with a DataTable class into a DataRelation.
Phew! And it works!
Dim tblSliceInfo As New DataTable("SliceInfo")
Dim tblSliceRatings As New DataTable("SliceRatings")
'.... All the adding datacolumns, datarows, etc. goes here..
DatasetInit.Tables.Add(tblSliceInfo)
|
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)
Constraint pk_table1 Primary Key,
|
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...
|
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,...
| |
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
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...
|
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...
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |