本文介绍了如何从int标识数据类型列分配值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个表,其列为'tx_id',数据类型为'int'标识。我想将此'tx_id'列的值分配给变量'v_txid'。 在以下代码中,'tx_id'数据列的实际值未正确分配。变量分配1而不是实际值,如666,677,678。 当我在SQL Query中使用相同的select语句时,它可以正常工作。 如何使它在C#中正常工作? SqlCommand cmd12 = new SqlCommand( SELECT c.categoryname,p.productname,t.categoryid,t.tx_id from txfile t join c in c.categoryid = t.categoryid在p.productid = t.productid上加入产品p WHERE t.CartTxNo =' + v_carttxno + '和labelgeneratedyesorno!='Y',sqlCon); SqlParameter param12 = new SqlParameter(); param12.ParameterName = @ v_carttxno; param12.Value = ss; cmd12.Parameters.Add(param12); sqlCon.Close(); sqlCon.Open(); SqlDataReader reader3 = cmd12.ExecuteReader(); if (reader3.HasRows) { while (reader3 .Read()) { v_categoryname = reader3.GetString( 0 ); v_productname = reader3.GetString( 1 ); int v_txid = reader3.GetInt32( 2 ); 解决方案 将索引更改为 3 int v_txid = reader3.GetInt32( 3 ); I have a table with a column as 'tx_id' and datatype is 'int' identity. I want to assign the values of this 'tx_id' column to a variable 'v_txid'. In the following code, the actual value of the 'tx_id' data column is not assigning correctly. The variable is assigned with 1 instead of actual value like 666,677,678. When I use the same select statement in SQL Query it works correctly. How to make it work correctly in C#?SqlCommand cmd12 = new SqlCommand("SELECT c.categoryname,p.productname,t.categoryid,t.tx_id from txfile t join category c on c.categoryid=t.categoryid join product p on p.productid=t.productid WHERE t.CartTxNo='" + v_carttxno + "' and labelgeneratedyesorno!='Y'", sqlCon); SqlParameter param12 = new SqlParameter(); param12.ParameterName = "@v_carttxno"; param12.Value = "ss"; cmd12.Parameters.Add(param12); sqlCon.Close(); sqlCon.Open(); SqlDataReader reader3 = cmd12.ExecuteReader(); if (reader3.HasRows) { while (reader3.Read()) { v_categoryname = reader3.GetString(0); v_productname = reader3.GetString(1); int v_txid = reader3.GetInt32(2); 解决方案 change the index to 3int v_txid = reader3.GetInt32(3); 这篇关于如何从int标识数据类型列分配值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-26 19:22