新手控制台输出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();
SqlDataReader r = SqlCmd.ExecuteReader();
while (r.Read())
{
Console.WriteLine(r.GetString(0));
}
}
catch (Exception e) { }
finally
{
SqlCon.Close();
}
}
}
}
我的数据库有3个字段,但是这里只能输入一个字段,应该怎么改啊?
------解决方案--------------------while (r.Read())
{
Console.WriteLine(r.GetString(0));
Console.WriteLine(r.GetString(1));
Console.WriteLine(r.GetString(2));
}