using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;namespace sqltest
{
class Program
{
static void Main(string[] args)
{
string ConStr = "Integrated Security=SSPI;database=kk;server=.";
SqlConnection SqlCon = new SqlConnection(ConStr);
string SelectCmd = "select * from student";
SqlCommand SqlCmd = new SqlCommand(SelectCmd,SqlCon);
try
{
SqlCon.Open();
SqlCmd.ExecuteNonQuery();
Console.WriteLine(SqlCmd);
}
catch (Exception e) { }
finally
{
SqlCon.Close();
}
}
}
}请问一下怎样才能在控制台下输入查询结果,我这样做输出的结果是错误的.!
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;namespace sqltest
{
class Program
{
static void Main(string[] args)
{
string ConStr = "Integrated Security=SSPI;database=kk;server=.";
SqlConnection SqlCon = new SqlConnection(ConStr);
string SelectCmd = "select * from student";
SqlCommand SqlCmd = new SqlCommand(SelectCmd,SqlCon);
try
{
SqlCon.Open();
SqlCmd.ExecuteNonQuery();
Console.WriteLine(SqlCmd);
}
catch (Exception e) { }
finally
{
SqlCon.Close();
}
}
}
}请问一下怎样才能在控制台下输入查询结果,我这样做输出的结果是错误的.!
解决方案 »
- dll依赖关系
- 谁能帮我翻译下这段python代码到c#
- C/S下如何实现电子地图?
- 2008系统无法生成程序日志
- 国外GIS平台比较!(arcinfo,smallworld,mapinfo,autoDesk,intergraph)
- 利用RAPI类库,通过MicroSoft ActiveSync实现PC与PPC之间的通讯
- 怎样混合编程
- 如何解决datagrid失去焦点时有时数据不能自动保存到datatable里面的问题?
- 如何将dataset的表赋给dataAdapter
- C# 多个自定义控件 怎么互不影响
- 帮帮小弟吧!!!这是我所有的 家当 了!!关于跨窗体托动的问题。
- 有没有人使用过DEVExpress,里的GridControl, 如何对其中一个栏位修改数据。
Console.WriteLine(SqlCmd);改成:
SqlDataReader r=new SqlDataReader (SqlCmd,con);
while(r.Read()){
Console.WriteLine(xxx);
}
SqlDataReader dr=SqlCmd.ExecuteReader();
try
{
SqlCon.Open();
while(dr.read())
{
Console.WriteLine(dr.GetString(0));
...........
}
}