【发布时间】:2014-01-26 05:10:10
【问题描述】:
我有一个绑定到 sqlserver 2012 数据库中的表的 datagridview。 所有字段都正确显示,除了显示为负数的主键字段。
这是什么原因造成的?
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Private Sub InitCommandCollection()
Me._commandCollection = New Global.System.Data.SqlClient.SqlCommand(1) {}
Me._commandCollection(0) = New Global.System.Data.SqlClient.SqlCommand()
Me._commandCollection(0).Connection = Me.Connection
Me._commandCollection(0).CommandText = "SELECT TSId, TCId, ElementNo, MSECId, UseInd, ElementDepth, ElementName, ChildInd"& _
", ElementValueDef, ElementValueNew, ElementPath, ElementPathFull, ElementValuePr"& _
"efix, ElementValueLength, ElementValueIncrement, UpperControlElement1, UpperCont"& _
"rolElementValue1, UpperControlElement2, UpperControlElementValue2, LowerControlE"& _
"lement1, LowerControlElementValue1, LowerControlElement2, LowerControlElementVal"& _
"ue2, AttributeName1, AttributeValue1, AttributeName2, AttributeValue2, Attribute"& _
"Name3, AttributeValue3, AttributeName4, AttributeValue4, AttributeName5, Attribu"& _
"teValue5 FROM dbo.XML_TEST_SET"
Me._commandCollection(0).CommandType = Global.System.Data.CommandType.Text
Me._commandCollection(1) = New Global.System.Data.SqlClient.SqlCommand()
Me._commandCollection(1).Connection = Me.Connection
Me._commandCollection(1).CommandText = "dbo.SP_XML_TEST_SET_FillByComboBoxes"
Me._commandCollection(1).CommandType = Global.System.Data.CommandType.StoredProcedure
Me._commandCollection(1).Parameters.Add(New Global.System.Data.SqlClient.SqlParameter("@RETURN_VALUE", Global.System.Data.SqlDbType.Int, 4, Global.System.Data.ParameterDirection.ReturnValue, 10, 0, Nothing, Global.System.Data.DataRowVersion.Current, false, Nothing, "", "", ""))
Me._commandCollection(1).Parameters.Add(New Global.System.Data.SqlClient.SqlParameter("@MyENVId", Global.System.Data.SqlDbType.Int, 4, Global.System.Data.ParameterDirection.Input, 10, 0, Nothing, Global.System.Data.DataRowVersion.Current, false, Nothing, "", "", ""))
Me._commandCollection(1).Parameters.Add(New Global.System.Data.SqlClient.SqlParameter("@MyUId", Global.System.Data.SqlDbType.Int, 4, Global.System.Data.ParameterDirection.Input, 10, 0, Nothing, Global.System.Data.DataRowVersion.Current, false, Nothing, "", "", ""))
Me._commandCollection(1).Parameters.Add(New Global.System.Data.SqlClient.SqlParameter("@MyMTId", Global.System.Data.SqlDbType.Int, 4, Global.System.Data.ParameterDirection.Input, 10, 0, Nothing, Global.System.Data.DataRowVersion.Current, false, Nothing, "", "", ""))
Me._commandCollection(1).Parameters.Add(New Global.System.Data.SqlClient.SqlParameter("@MyTestSetName", Global.System.Data.SqlDbType.NVarChar, 2147483647, Global.System.Data.ParameterDirection.Input, 0, 0, Nothing, Global.System.Data.DataRowVersion.Current, false, Nothing, "", "", ""))
Me._commandCollection(1).Parameters.Add(New Global.System.Data.SqlClient.SqlParameter("@MyTestCaseName", Global.System.Data.SqlDbType.NVarChar, 2147483647, Global.System.Data.ParameterDirection.Input, 0, 0, Nothing, Global.System.Data.DataRowVersion.Current, false, Nothing, "", "", ""))
Me._commandCollection(1).Parameters.Add(New Global.System.Data.SqlClient.SqlParameter("@MyInterchangeSeqNo", Global.System.Data.SqlDbType.Int, 4, Global.System.Data.ParameterDirection.Input, 10, 0, Nothing, Global.System.Data.DataRowVersion.Current, false, Nothing, "", "", ""))
Me._commandCollection(1).Parameters.Add(New Global.System.Data.SqlClient.SqlParameter("@MyInstructionSeqNo", Global.System.Data.SqlDbType.Int, 4, Global.System.Data.ParameterDirection.Input, 10, 0, Nothing, Global.System.Data.DataRowVersion.Current, false, Nothing, "", "", ""))
Me._commandCollection(1).Parameters.Add(New Global.System.Data.SqlClient.SqlParameter("@MyTransactionSeqNo", Global.System.Data.SqlDbType.Int, 4, Global.System.Data.ParameterDirection.Input, 10, 0, Nothing, Global.System.Data.DataRowVersion.Current, false, Nothing, "", "", ""))
Me._commandCollection(1).Parameters.Add(New Global.System.Data.SqlClient.SqlParameter("@MyElementValueDef", Global.System.Data.SqlDbType.NVarChar, 2147483647, Global.System.Data.ParameterDirection.Input, 0, 0, Nothing, Global.System.Data.DataRowVersion.Current, false, Nothing, "", "", ""))
Me._commandCollection(1).Parameters.Add(New Global.System.Data.SqlClient.SqlParameter("@MyElementPathFull", Global.System.Data.SqlDbType.NVarChar, 2147483647, Global.System.Data.ParameterDirection.Input, 0, 0, Nothing, Global.System.Data.DataRowVersion.Current, false, Nothing, "", "", ""))
Me._commandCollection(1).Parameters.Add(New Global.System.Data.SqlClient.SqlParameter("@MyFetchRows", Global.System.Data.SqlDbType.Int, 4, Global.System.Data.ParameterDirection.Input, 10, 0, Nothing, Global.System.Data.DataRowVersion.Current, false, Nothing, "", "", ""))
End Sub
存储过程:
USE [UToolDb]
去 设置 ANSI_NULLS ON 走 设置 QUOTED_IDENTIFIER ON 走 更改程序 [dbo].[SP_XML_TEST_SET_FillByComboBoxes] -- 这里添加存储过程的参数 @MyENVId 作为 INT, @MyUId 作为 INT, @MyMTId 作为 INT, @MyTestSetName AS NVARCHAR(MAX), @MyTestCaseName AS NVARCHAR(MAX), @MyInterchangeSeqNo AS INT, @MyInstructionSeqNo 作为 INT, @MyTransactionSeqNo 作为 INT, @MyElementValueDef AS NVARCHAR(MAX), @MyElementPathFull AS NVARCHAR(MAX), @MyFetchRows AS INT
作为 开始 -- 添加了 SET NOCOUNT ON 以防止额外的结果集 -- 干扰 SELECT 语句。 设置无计数;
SET ROWCOUNT @MyFetchRows
DECLARE @sql NVARCHAR(MAX) = N'
SELECT
TS.TCId,
TS.ElementNo,
TS.MSECId,
TS.UseInd,
TS.ElementDepth,
TS.ElementName,
TS.ChildInd,
TS.ElementValueDef,
TS.ElementValueNew,
TS.ElementPath,
TS.ElementPathFull,
TS.ElementValuePrefix,
TS.ElementValueLength,
TS.ElementValueIncrement,
TS.UpperControlElement1,
TS.UpperControlElementValue1,
TS.UpperControlElement2,
TS.UpperControlElementValue2,
TS.LowerControlElement1,
TS.LowerControlElementValue1,
TS.LowerControlElement2,
TS.LowerControlElementValue2,
TS.AttributeName1,
TS.AttributeValue1,
TS.AttributeName2,
TS.AttributeValue2,
TS.AttributeName3,
TS.AttributeValue3,
TS.AttributeName4,
TS.AttributeValue4,
TS.AttributeName5,
TS.AttributeValue5
FROM dbo.XML_TEST_SET TS
LEFT JOIN dbo.XML_TEST_SET_OVERVIEW TSO
ON TSO.TCId = TS.TCId '
+ CASE WHEN (@MyENVId IS NOT NULL) THEN N'WHERE TSO.ENVId = @MyENVId ' ELSE 'WHERE TSO.ENVId IS NOT NULL ' END
+ CASE WHEN (@MyUId IS NOT NULL) THEN N'AND TSO.UId = @MyUId ' ELSE '' END
+ CASE WHEN (@MyMTId IS NOT NULL) THEN N'AND TSO.MTId = @MyMTId ' ELSE '' END
+ CASE WHEN (@MyTestSetName IS NOT NULL) THEN N'AND TSO.TestSetName = @MyTestSetName ' ELSE '' END
+ CASE WHEN (@MyTestCaseName IS NOT NULL) THEN N'AND TSO.TestCaseName = @MyTestCaseName ' ELSE '' END
+ CASE WHEN (@MyInterchangeSeqNo IS NOT NULL) THEN N'AND TSO.TestCaseName = @MyTestCaseName ' ELSE '' END
+ CASE WHEN (@MyInstructionSeqNo IS NOT NULL) THEN N'AND TSO.TestCaseName = @MyTestCaseName ' ELSE '' END
+ CASE WHEN (@MyTransactionSeqNo IS NOT NULL) THEN N'AND TSO.TransactionSeqNo = @MyTransactionSeqNo ' ELSE '' END
+ CASE WHEN (@MyElementValueDef IS NOT NULL) THEN N'AND TS.ElementValueDef = @MyElementValueDef ' ELSE '' END
+ CASE WHEN (@MyElementPathFull IS NOT NULL) THEN N'AND TS.ElementPathFull = @MyElementPathFull ' ELSE '' END
+ N'ORDER BY TSO.TestSetName, TSO.TestCaseName, TS.ElementNo, TSO.InterchangeSeqNo, TSO.InstructionSeqNo, TSO.TransactionSeqNo;';
执行 sp_executesql @sql, N' @MyENVId INT, @MyUId INT, @MyMTId INT, @MyTestSetName NVARCHAR(MAX), @MyTestCaseName NVARCHAR(MAX), @MyInterchangeSeqNo SMALLINT, @MyInstructionSeqNo SMALLINT, @MyTransactionSeqNo SMALLINT, @MyElementValueDef NVARCHAR(MAX), @MyElementPathFull NVARCHAR(MAX)', @MyENVId、@MyUId、@MyMTId、@MyTestSetName、@MyTestCaseName、@MyInterchangeSeqNo、@MyInstructionSeqNo、@MyTransactionNSeqNo、@MyElementValueDef、@MyElementPathFull; 结束
【问题讨论】:
标签: vb.net datagridview sql-server-2012