新手控制台输出SQL问题

edisonlzk 2007-08-23 11:57:46
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个字段,但是这里只能输入一个字段,应该怎么改啊?
...全文
76 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
edisonlzk 2007-08-23
  • 打赏
  • 举报
回复
这样不对,我都试过了,
只能输入一条记录,系统就记录按任意键继续.!
BearRui 2007-08-23
  • 打赏
  • 举报
回复
while (r.Read())
{
Console.WriteLine(r.GetString(0));
Console.WriteLine(r.GetString(1));
Console.WriteLine(r.GetString(2));
}

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧