使用Drag& amp;创建的默认方法删除尝试编辑Primary K. [英] Default Methods created with Drag & Drop attempt to edit Primary K

查看:65
本文介绍了使用Drag& amp;创建的默认方法删除尝试编辑Primary K.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VB 2005,并且在我的表单上有药物并丢弃了datagridviews。为插入生成的

默认代码尝试为

自动生成的主键插入值。下面是生成的代码。我把问题代码放在了

周围。我试过删除这个,但似乎没有工作。可能有更多生成的代码我不知道。我可以删除

但我计划对数据源进行大量更新

意味着我每次刷新时都需要编辑大量代码。这是

只是微软的疏忽吗?我似乎VS 2005会检查

如果列是自动递增的,如果它不会尝试在其中插入

值?


我可以在桌子上放置一个设置,以便正确生成

吗?我对ID列的Idenitty规范是肯定的,

为1增量。在我生成的更新语句中也有类似的问题。

自动生成的代码无法更新具有标识的主键

规范设置为yes。我觉得这不应该发生吗?这只是

微软的监督吗?


< System.Diagnostics.DebuggerNonUserCodeAttribute(),_


System.ComponentModel.Design.HelpKeywordAttribute(" versusdata.TableAdapter"),_


System.ComponentModel.DataObjectMethodAttribute(Sy stem.ComponentModel.DataObjectMethodType.Insert,true)> ; _

公共重载可覆盖函数插入(ByVal CompositionID为

整数,ByVal CompositionName为字符串,ByVal CompDesc为字符串,ByVal

密度为双)作为整数

****** Me.Adapter.InsertCommand.Parameters(0).Value =

CType(CompositionID,Integer)****** *

如果(CompositionName没什么)那么

Me.Adapter.InsertCommand.Parameters(1).Value =

System.DBNull.Value

Else

Me.Adapter.InsertCommand.Parameters(1).Value =

CType(CompositionName,String)

结束如果

如果(CompDesc什么都没有)那么

Me.Adapter.InsertCommand.Parameters(2).Value =

系统。 DBNull.Value

Else

Me.Adapter.InsertCommand.Parameters(2).Value =

CType(CompDesc,String)

结束如果

Me.Adapter.InsertCommand.Parameters(3).Value =

CType(密度,双倍)

Dim previousConnectionState As System.Data.Conn ectionState =

Me.Adapter.InsertCommand.Connection.State

If((Me.Adapter.InsertCommand.Connection.State和

系统。 Data.ConnectionState.Open)_

<> System.Data.ConnectionState.Open)然后

Me.Adapter.InsertCommand.Connection.Open

结束如果

试试

Dim returnValue As Integer =

Me.Adapter.InsertCommand.ExecuteNonQuery

返回returnValue

最后

if(previousConnectionState =

System.Data.ConnectionState.Closed)然后

Me.Adapter.InsertCommand.Connection.Close

结束如果

结束尝试

结束功能


谢谢,

格雷格

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

推荐答案

请不要宣传使用身份作为主键来回复

这篇文章。我知道这不是最好的形式。我知道它是
是将应用程序的一部分存储在数据库中,但我还没准备好

此时重建我的整个数据库。有没有办法让它按照我想要的方式工作




" Greg P"写道:
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:
我正在使用VB 2005,并且在我的表单上有药物并删除了datagridviews。为插入生成的
默认代码尝试为
自动生成的主键插入值。下面是生成的代码。我把*****围绕着有问题的代码。我试过删除它,但似乎没有工作。可能有更多生成的代码我不知道。我可以删除它但我计划对数据源进行大量更新,这意味着每次刷新时我都需要编辑大量的代码。这是否只是微软的疏忽?我似乎VS 2005会检查
列是否自动递增,如果是,它不会尝试在其中插入
值?

是有一个设置我可以放在我的桌子上,以便正确生成吗?我对ID列的Idenitty规范是肯定的,
为1增量。在我生成的更新语句中也有类似的问题。
自动生成的代码无法更新将Identity
规范设置为yes的主键。我觉得这不应该发生吗?这只是
微软的疏忽

< System.Diagnostics.DebuggerNonUserCodeAttribute(),_

System.ComponentModel.Design.HelpKeywordAttribute(" VS .data.TableAdapter"),_

System.ComponentModel.DataObjectMethodAttribute(Sy stem.ComponentModel.DataObjectMethodType.Insert,true)> _
公共重载可覆盖函数插入(ByVal CompositionID为
整数,ByVal CompositionName为字符串,ByVal CompDesc为字符串,ByVal
密度为双)作为整数
***** * Me.Adapter.InsertCommand.Parameters(0).Value =
CType(CompositionID,Integer)*******
If(CompositionName Is Nothing)然后
Me.Adapter。 InsertCommand.Parameters(1).Value =
System.DBNull.Value
Else
Me.Adapter.InsertCommand.Parameters(1).Value =
CType(CompositionName,String)
结束如果
如果(CompDesc什么都没有)那么
Me.Adapter.InsertCommand.Parameters(2).Value =
System.DBNull.Value
Else
Me.Adapter.InsertCommand.Parameters(2).Value =
CType(CompDesc,String)
结束如果
Me.Adapter.InsertCommand.Parameters(3).Value =
CType(密度,双倍)
Dim previousConnectionState As System.Data.ConnectionState =
Me.Adapter.InsertCommand.Connection.State
If((Me.Adapter.InsertCommand.Connection.State和
System.Data。 ConnectionState.Open)_
<> System.Data.ConnectionState.Open)然后
Me.Adapter.InsertCommand.Connection.Open
结束如果
尝试
Dim returnValue As Integer =
Me.Adapter。 InsertCommand.ExecuteNonQuery
返回returnValue
最后
if(previousConnectionState =
System.Data.ConnectionState.Closed)然后
Me.Adapter.InsertCommand.Connection.Close 结束功能

谢谢,
Greg
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



您好,


感谢您的发布。目前我们正在寻找合适的资源

帮助您解决这个问题,并会尽快给您更新。


问候,

Luke Zhang

Microsoft在线社区支持


=================== ===============================

在回复帖子时,请回复群组 ;通过你的新闻阅读器

其他人可以从你的问题中学习并从中受益。

==================== ==============================


(此帖子提供AS IS,没有任何保证,并且不授予

权利。)

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,我希望我不会太过坦率地说明身份栏上的帖子b / ing
a主键。 VB 2005如何处理任何标识列是否是一个

主键?


谢谢,

Greg P


" Luke Zhang [MSFT]"写道:
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:
您好,

感谢您的发布。目前我们正在寻找合适的资源来帮助您解决这个问题,并会尽快给您更新。

问候,

Luke Zhang
微软在线社区支持

======================================= ===========
在回复帖子时,请回复群组通过您的新闻阅读器,以便其他人可以从您的问题中学习并从中受益。
============================ ======================

(此帖子按原样提供,没有任何保证,并且不授予
权利。)
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.)



这篇关于使用Drag&amp; amp;创建的默认方法删除尝试编辑Primary K.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆