sql控制台程序问题
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();
}
}
}
}
请问一下怎样才能在控制台下输入查询结果,我这样做输出的结果是错误的.!
------解决方案--------------------SqlCmd.ExecuteNonQuery();
Console.WriteLine(SqlCmd);
改成:
SqlDataReader r=new SqlDataReader (SqlCmd,con);
while(r.Read()){
Console.WriteLine(xxx);
}