首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

新手控制台输出SQL有关问题

2012-03-20 
新手控制台输出SQL问题usingSystemusingSystem.Collections.GenericusingSystem.TextusingSystem.Data

新手控制台输出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));
}

热点排行