比如:
1.select name from table where id=9 这里怎么把取出的name值赋给string类型的变量strName?
2.select name from table 这里怎么把取出的name值赋给string类型的数组strName[]?
3.select count(name) from table 这里怎么把取出的count值赋给int类型的变量一iCount?
1.select name from table where id=9 这里怎么把取出的name值赋给string类型的变量strName?
2.select name from table 这里怎么把取出的name值赋给string类型的数组strName[]?
3.select count(name) from table 这里怎么把取出的count值赋给int类型的变量一iCount?
解决方案 »
- 计算机系毕业设计的几个问题,求前辈的经验
- 关于注册表操作权限的问题
- 求解一个treeview的递归算法!!
- 如何将ListView控件选中的项向上移动或向下移动
- 急!!!会的说说……
- 截取字符串问题,请高手帮忙!
- 在一个winform切换不同的panel导致的System.Runtime.InteropServices.SEHException,高分求解!
- 怎样重写Log4net中的Appender了?
- 请问如何从一张表中取得约束关系呢?
- 请大家讨论(请斑竹置顶)
- image->Dispose() 怎么有问题
- 平铺窗口的问题,主窗口上面有个treeview控件,在运行之后,随着主界面最大化,而treeview的高度也随着主界面而变化.
string strName = SqlCommand1.ExecuteScalar().ToString();2.
将结果放到DataSet中,
int resCount = DataSet1.Tables[0].Rows.Count;
string[] strName = new string[resCount];
for(int i = 0; i < resCount; i ++)
{
DataRow row = DataSet1.Tables[0].Rows[i];
strName[i] = row["name"].ToString();
}3.
Int32 iCcount = (int32)SqlCommand1.ExecuteScalar();
cmd_sql.Connection=cnn;
cmd_sql.CommandText="select * from table where id=12";
try
{
cnn.Open();
SqlDataReader dr=cmd_sql.ExecuteReader();
if(dr.Read())
{
strName=dr["name"].ToString();
}
}
catch(Exception err)
{
return null;
}
finally
{
cnn.Close();
}
类似的解决你其它两个问题如果是多条的则用
int i=0 ;
while(dr.read())
{
strName[i]=dr["Name"].toString();
i++;
}而select count(name) from table
则改为select count(name) as cunt from table
最后取值为iCount=Convert.toint32(dr["cunt"].toString())