G
Guest
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(System.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
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(System.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