string strSql,strConn,num;
int maxvalue ;
maxvalue = 0;
strConn = WebConfigurationManager.ConnectionStrings[1].ConnectionString;
strSql = "select max(substring(gcbm,16,2)) as maxvalue from sggcjbqkb where substring(gcbm,7,8)='"+dd +"'";
SqlConnection sc = new SqlConnection();
sc.ConnectionString = strConn;
sc.Open(); Response.Write(maxvalue);
num = Convert.ToString(maxvalue + 1);-----------sql语句
strSql = "select max(substring(gcbm,16,2)) as maxvalue from sggcjbqkb where substring(gcbm,7,8)='"+dd +"'";
中的maxvalue的值在程序运运
int maxvalue ;
maxvalue = 0;
strConn = WebConfigurationManager.ConnectionStrings[1].ConnectionString;
strSql = "select max(substring(gcbm,16,2)) as maxvalue from sggcjbqkb where substring(gcbm,7,8)='"+dd +"'";
SqlConnection sc = new SqlConnection();
sc.ConnectionString = strConn;
sc.Open(); Response.Write(maxvalue);
num = Convert.ToString(maxvalue + 1);-----------sql语句
strSql = "select max(substring(gcbm,16,2)) as maxvalue from sggcjbqkb where substring(gcbm,7,8)='"+dd +"'";
中的maxvalue的值在程序运运
解决方案 »
- 在asp.net里面套google站内搜索报错
- asp页与asp.net页面 cookie取不到了
- 帮我看下这个存储过程的@Where查询条件怎么写?
- GridView分页问题
- timeout超时??
- 打开rational rose2003的.mdl文件不成功,显示resolving reference 81%就停止了
- 如何在OA里发短信?用短信猫。
- 未能在“设计”视图中打开,为什么阿
- 谁能给一个 Parameters 的例
- 大家介绍一个简单的文本编辑控件吧.freetextbox和fck都太麻烦了,特别是图片上传功能.立马给分!
- repeater嵌套,大家帮我找找错在哪????
- .net 中怎么把文本转成SQL binary类型
int maxvalue ;
maxvalue = 0;
strConn = WebConfigurationManager.ConnectionStrings[1].ConnectionString;
strSql = "select max(substring(gcbm,16,2)) as maxvalue from sggcjbqkb where substring(gcbm,7,8)='"+dd +"'";
SqlConnection sc = new SqlConnection();
sc.ConnectionString = strConn;
sc.Open(); Response.Write(maxvalue);
num = Convert.ToString(maxvalue + 1);========================
strSql = "select max(substring(gcbm,16,2)) as maxvalue from sggcjbqkb where substring(gcbm,7,8)='"+dd +"'";
写这个语句是为了得到最大值,我把这个语句在数据库里执xing的时候,可以得到最大值,但是在程序运行的时候,我设断点查看到的值为0,为什么不能正确的返回值?
你需要用SqlDataReader 或者DataSet对象,然后将取得的值赋给maxvalue。如:
SqlCommand myCmd=new SqlCommand(strSql,strConn);
SqlDataReader myReader=myCmd.ExecuteReader();
if(myReader.Read())
{
maxvalue=int.Parse(myReader["maxvalue"].ToString());
}
根本就没有被类似与sqldataadapter或者sqlcommand来执行!!!
cmd.ExecuteScalar();返回首行首列