首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

如何将SQl中查询的一行一列的值传送到C#中的变量

2012-10-21 
怎么将SQl中查询的一行一列的值传送到C#中的变量SQL语句selectwname from tablename where wnoxxx[

怎么将SQl中查询的一行一列的值传送到C#中的变量
SQL语句"select wname from tablename where wno="xxx"";

[解决办法]
ADO.NET

C# code
string retVal = "";string sql = "select wname from tablename where wno='xxx'";using (SqlConnection conn = new SqlConnection(connectionString)){    SqlCommand cmd = new SqlCommand();    cmd.CommandText = strSql;    cmd.CommandType = CommandType.Text;    cmd.Connection = conn;    conn.Open();    retVal = cmd.ExecuteScalar().ToString();    conn.Close();}return retVal; 

热点排行