I'm using VB 2005, and have drug and dropped datagridviews onto my form. The
default code that is generated for inserts tries to insert a value for the
auto generated primary key. Below is the generated code. I put ***** around
the problematic code. I've tried just removing this and it doesn't seem to
work. There may be more generated code I don't know about. I could remove
it but I am planning on doing a lot of refreshing of the data source which
would mean I would need to edit a ton of code each time I refreshed. Is this
just an oversight by microsoft? I would seem that VS 2005 would check to see
if a column is auto incremented and if it was it wouldn't try to insert a
value into it?
Is there a setting I can place on my table so that this is generated
correctly? My Idenitty specification for the ID column is seet to yes, with
a 1 increment. In my generated Update statments there are similar issues.
The auto generated code tires to update a primary key that has Identity
Specification set to yes. I would think This shouldn't happen? Is this just
an oversight by Microsoft?
<System.Diagnostics.DebuggerNonUserCodeAttribute() , _
System.ComponentModel.Design.HelpKeywordAttribute( "vs.data.TableAdapter"), _
System.ComponentModel.DataObjectMethodAttribute(Sy stem.ComponentModel.DataObjectMethodType.Insert, true)> _
Public Overloads Overridable Function Insert(ByVal CompositionID As
Integer, ByVal CompositionName As String, ByVal CompDesc As String, ByVal
Density As Double) As Integer
****** Me.Adapter.InsertCommand.Parameters(0).Value =
CType(CompositionID,Integer) *******
If (CompositionName Is Nothing) Then
Me.Adapter.InsertCommand.Parameters(1).Value =
System.DBNull.Value
Else
Me.Adapter.InsertCommand.Parameters(1).Value =
CType(CompositionName,String)
End If
If (CompDesc Is Nothing) Then
Me.Adapter.InsertCommand.Parameters(2).Value =
System.DBNull.Value
Else
Me.Adapter.InsertCommand.Parameters(2).Value =
CType(CompDesc,String)
End If
Me.Adapter.InsertCommand.Parameters(3).Value =
CType(Density,Double)
Dim previousConnectionState As System.Data.ConnectionState =
Me.Adapter.InsertCommand.Connection.State
If ((Me.Adapter.InsertCommand.Connection.State And
System.Data.ConnectionState.Open) _
<> System.Data.ConnectionState.Open) Then
Me.Adapter.InsertCommand.Connection.Open
End If
Try
Dim returnValue As Integer =
Me.Adapter.InsertCommand.ExecuteNonQuery
Return returnValue
Finally
If (previousConnectionState =
System.Data.ConnectionState.Closed) Then
Me.Adapter.InsertCommand.Connection.Close
End If
End Try
End Function
Thanks,
Greg 11 1956
Please do not preach about using an identity as a primary key in response to
this post. I understand that it isn't the best form. I understand that it
is "storing part of the application in the database", but I'm not ready to
rebuild my entire database at this time. Is there a way to get this to work
the way I want it to?
"Greg P" wrote: I'm using VB 2005, and have drug and dropped datagridviews onto my form. The default code that is generated for inserts tries to insert a value for the auto generated primary key. Below is the generated code. I put ***** around the problematic code. I've tried just removing this and it doesn't seem to work. There may be more generated code I don't know about. I could remove it but I am planning on doing a lot of refreshing of the data source which would mean I would need to edit a ton of code each time I refreshed. Is this just an oversight by microsoft? I would seem that VS 2005 would check to see if a column is auto incremented and if it was it wouldn't try to insert a value into it?
Is there a setting I can place on my table so that this is generated correctly? My Idenitty specification for the ID column is seet to yes, with a 1 increment. In my generated Update statments there are similar issues. The auto generated code tires to update a primary key that has Identity Specification set to yes. I would think This shouldn't happen? Is this just an oversight by Microsoft?
<System.Diagnostics.DebuggerNonUserCodeAttribute() , _
System.ComponentModel.Design.HelpKeywordAttribute( "vs.data.TableAdapter"), _
System.ComponentModel.DataObjectMethodAttribute(Sy stem.ComponentModel.DataObjectMethodType.Insert, true)> _ Public Overloads Overridable Function Insert(ByVal CompositionID As Integer, ByVal CompositionName As String, ByVal CompDesc As String, ByVal Density As Double) As Integer ****** Me.Adapter.InsertCommand.Parameters(0).Value = CType(CompositionID,Integer) ******* If (CompositionName Is Nothing) Then Me.Adapter.InsertCommand.Parameters(1).Value = System.DBNull.Value Else Me.Adapter.InsertCommand.Parameters(1).Value = CType(CompositionName,String) End If If (CompDesc Is Nothing) Then Me.Adapter.InsertCommand.Parameters(2).Value = System.DBNull.Value Else Me.Adapter.InsertCommand.Parameters(2).Value = CType(CompDesc,String) End If Me.Adapter.InsertCommand.Parameters(3).Value = CType(Density,Double) Dim previousConnectionState As System.Data.ConnectionState = Me.Adapter.InsertCommand.Connection.State If ((Me.Adapter.InsertCommand.Connection.State And System.Data.ConnectionState.Open) _ <> System.Data.ConnectionState.Open) Then Me.Adapter.InsertCommand.Connection.Open End If Try Dim returnValue As Integer = Me.Adapter.InsertCommand.ExecuteNonQuery Return returnValue Finally If (previousConnectionState = System.Data.ConnectionState.Closed) Then Me.Adapter.InsertCommand.Connection.Close End If End Try End Function
Thanks, Greg
Hello,
Thank you for the posting. Currently we are finding proper resource to
assist you on this issue and will update you as soon as possible.
Regards,
Luke Zhang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Luke,
Thanx, I hope I wasn't too frank with the post on the Identity column bieing
a primary key. How would VB 2005 handle any identity column whether it is a
primary key or not?
Thanks,
Greg P
"Luke Zhang [MSFT]" wrote: Hello,
Thank you for the posting. Currently we are finding proper resource to assist you on this issue and will update you as soon as possible.
Regards,
Luke Zhang Microsoft Online Community Support
================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ==================================================
(This posting is provided "AS IS", with no warranties, and confers no rights.)
Hi Greg,
Yes, as you know, if the column in database is a Primary Key and is
auto-increment, VS.NET designer will not generate parameter for this
column. Because this column is readonly, and the value in it can only be
generated by SQL Server itself. This is by design, and unfortunately there
is no option that we can set to change the behavior.
Kevin Yu
Microsoft Online Community Support
================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Kevin,
That is exactly what I would expect, but not what I see. This should be a
very simple test, create a table that has an auto incremented indentity
column, use the datasource wizard, drag and drop a dataGridView and look at
the code. You will see in the insert and update that it refences the field
as shown in my code posted above.
Thanks for your time,
Greg
"Kevin Yu [MSFT]" wrote: Hi Greg,
Yes, as you know, if the column in database is a Primary Key and is auto-increment, VS.NET designer will not generate parameter for this column. Because this column is readonly, and the value in it can only be generated by SQL Server itself. This is by design, and unfortunately there is no option that we can set to change the behavior.
Kevin Yu Microsoft Online Community Support
================================================== ========================== ========================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== ========================== ==========================
(This posting is provided "AS IS", with no warranties, and confers no rights.)
Kevin,
Just to be sure I wasn't missing something I just ran this test and saw the
same result. Then I removed the table from the datasource and added it back
and it worked correctly. Maybe I don't understand when the designer code
gets refreshed? I thought that everytime you connected to the database the
designer code gets rewritten? The issue here was that I changed the database
after I had added the datasource. I then used the wizard to go and get those
changes and it didn't. I had to remove the table from the dataset and add it
again. Is this the expected behavior?
The reason I ask is if I change some of the designer code I thought it would
be overwritten when I refreshed the dataset though the wizard? If this isn't
the case then that gives me more flexability in changing some of the auto
generated code.
Thanks,
Greg P.
"Kevin Yu [MSFT]" wrote: Hi Greg,
Yes, as you know, if the column in database is a Primary Key and is auto-increment, VS.NET designer will not generate parameter for this column. Because this column is readonly, and the value in it can only be generated by SQL Server itself. This is by design, and unfortunately there is no option that we can set to change the behavior.
Kevin Yu Microsoft Online Community Support
================================================== ========================== ========================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== ========================== ==========================
(This posting is provided "AS IS", with no warranties, and confers no rights.)
Hi Greg,
As I tried on my machine, the auto-increment columns will not be included
in the column list in insert and update commands. The generated code will
not get refreshed when the database table changes. To make the changes
reflect in DataSet designer, the only way to to go throught the wizard
again. Because drag and drop from the server explorer is only for designer
convenience. The client code is not assured to change with the server table.
Kevin Yu
Microsoft Online Community Support
================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Kevin,
I think this may be a bug then, becuase after I have changed the table and
then go through the designer again the generated code doesn't change. The
column is still there. The only way I can change it is to remove the table
through the designer and then re-add it. Is this the expected behavior?
Thanks,
Greg
"Kevin Yu [MSFT]" wrote: Hi Greg,
As I tried on my machine, the auto-increment columns will not be included in the column list in insert and update commands. The generated code will not get refreshed when the database table changes. To make the changes reflect in DataSet designer, the only way to to go throught the wizard again. Because drag and drop from the server explorer is only for designer convenience. The client code is not assured to change with the server table.
Kevin Yu Microsoft Online Community Support
================================================== ========================== ========================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== ========================== ==========================
(This posting is provided "AS IS", with no warranties, and confers no rights.)
Hi Greg,
If the column is already there, the wizard will not automatically remove
it. You can try to remove the table in the query build and re-add it. Or
remove the table in the DataSet designer and re-add it. They seem to be the
only way here.
Kevin Yu
Microsoft Online Community Support
================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Kevin,
I just wanted to make sure I follow up on this and I am clear. This isn't a
bug and this is the expected behavior for the dataset designer? If you make
changes to a table after you have already created a dataset you would have to:
1) Open the designer, uncheck table finsih the designer
2) Then reopen it again an select the table a second time and finish again.
I would have expected that if you have a table already in your Dataset and
then you selected the table through the dataset designer the first time, VS
would delete any generated code and regenerate the code based on the updated
table?
If not that cool too, I just want to make sure this isn't a bug and I
understand it correctly.
Thanks,
Greg
"Kevin Yu [MSFT]" wrote: Hi Greg,
If the column is already there, the wizard will not automatically remove it. You can try to remove the table in the query build and re-add it. Or remove the table in the DataSet designer and re-add it. They seem to be the only way here.
Kevin Yu Microsoft Online Community Support
================================================== ========================== ========================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== ========================== ==========================
(This posting is provided "AS IS", with no warranties, and confers no rights.)
Hi Greg,
Yes, this is not a bug an it is by design. And your steps are correct.
Kevin Yu
Microsoft Online Community Support
================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================
(This posting is provided "AS IS", with no warranties, and confers no
rights.) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Anthony Baxter |
last post by:
To go along with the 2.4a3 release, here's an updated version of
the decorator PEP. It describes the state of decorators as they
are in 2.4a3.
PEP: 318
Title: Decorators for Functions and...
|
by: srikanth |
last post by:
Hi all,
I have an requirement in one of my projects.
We have one aspx page, in that we have two frames, in each
frame having a tree structure control(dynamic data).
In the left Frame we are...
|
by: Plumer |
last post by:
Hello everyone,
Yesterday I posted a message about implementing drag & drop in a TreeView
control.
I'm having real difficulty getting this to work -- the process seems to be
incredibly...
|
by: Ian D |
last post by:
Firstly apologies for the convoluted question. I found this problem whilst
building a larger database. I've distilled it down to as small as possible
and can send a 200k example to anyone who has...
|
by: jojobar |
last post by:
Hello,
I look at the asp.net 2.0 web parts tutorial on the asp.net web site. I
tried to run it under firefox browser but it did not run.
If I want to use this feature in a commercial product...
|
by: Terry Olsen |
last post by:
My first time using TreeViews. I have TreeView1 set up to display my
directory structure just like Windows Explorer. I can drag & drop files and
folders over to TreeView2. I can re-arrange the...
|
by: joey.powell |
last post by:
I have a Windows Forms application where I need to be able to drag and
then drop onto a datagridview control. I already have the code
necessary to make the drag part work. I am having problems,...
|
by: mike0870 |
last post by:
Hi, I've been at this one for hours and cannot not find any posts of anyone having the same problem. Ther scenario is, I need to fill a drop down box with a value in the grid row to pass to the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
| |