怎样将sql语句select的结果赋值给paramter.value?谢谢!请进! 如题!select zyno from zydm where zyname=combobox1.textSqlParamter paramter=? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可以先求出select语句的结果,比如写个函数,之后再赋值就OK了 /// <summary> /// 返回SQL语句执行结果的第一行第一列 /// </summary> /// <returns>字符串</returns> public string ReturnValue(string SQL) { SqlConnection Conn; Conn = new SqlConnection(ConnStr); Conn.Open(); string result; SqlDataReader Dr ; try { Dr = CreateCmd(SQL, Conn).ExecuteReader(); if(Dr.Read()) { result = Dr[0].ToString(); Dr.Close(); } else { result = ""; Dr.Close(); } } catch { throw new Exception(SQL); } Dispose(Conn); return result; }用这个函数吧。就不要SqlParamter 来返回值了。或者改为存储过程,SqlParamter 的类型设为output public SqlCommand CreateCmd(string SQL,SqlConnection Conn) { SqlCommand Cmd ; Cmd = new SqlCommand(SQL, Conn); return Cmd; } /// <summary> /// 生成Command对象 /// </summary> /// <param name="SQL"></param> /// <returns></returns> public SqlCommand CreateCmd(string SQL) { SqlConnection Conn = new SqlConnection(ConnStr); Conn.Open(); SqlCommand Cmd ; Cmd = this.CreateCmd(SQL, Conn); return Cmd; } 后缀名问题 VS添加access数据库为什么界面和别人的不一样 一个窗口登录验证的问题! 严重问题 C#语言怎么在向TXT文件写入数据的时候,在取文件中的行数呢?? 小妹向各位前辈请教:向listview添加checkbox和comboBox 大数库更新100分[在线等] 关于C#的命名空间,谢谢! 哪位帮我看看我的这段C#代码在IIS里添加虚拟目录提示拒绝访问的错误 c#的客户端能不能调用WebService定义的全局变量啊?如果能怎样调用啦? 如何改变StackPanel的显示样式呢? 可否把mp3文件嵌入到资源里然后播放 Socket编程的问题
/// 返回SQL语句执行结果的第一行第一列
/// </summary>
/// <returns>字符串</returns>
public string ReturnValue(string SQL)
{
SqlConnection Conn;
Conn = new SqlConnection(ConnStr);
Conn.Open();
string result;
SqlDataReader Dr ;
try
{
Dr = CreateCmd(SQL, Conn).ExecuteReader();
if(Dr.Read())
{
result = Dr[0].ToString();
Dr.Close();
}
else
{
result = "";
Dr.Close();
}
}
catch
{
throw new Exception(SQL);
}
Dispose(Conn);
return result;
}
用这个函数吧。就不要SqlParamter 来返回值了。或者改为存储过程,SqlParamter 的类型设为output
{
SqlCommand Cmd ;
Cmd = new SqlCommand(SQL, Conn);
return Cmd;
}
/// <summary>
/// 生成Command对象
/// </summary>
/// <param name="SQL"></param>
/// <returns></returns>
public SqlCommand CreateCmd(string SQL)
{
SqlConnection Conn = new SqlConnection(ConnStr);
Conn.Open();
SqlCommand Cmd ;
Cmd = this.CreateCmd(SQL, Conn);
return Cmd;
}