using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;namespace datebase
{
    class SqlOperateInfo    {
        static void Main(string[] args)
        {
            SqlConnection conn = new SqlConnection("Server=localhost; Initial Catalog=stuinfo_table; User ID=sa; Password=123;");
            
            SqlCommand Scommand = new SqlCommand();
            Scommand.Connection = conn;
            Scommand.CommandType = "select * from stuinfo_table";            conn.Open();            SqlDataReader sdr;
            sdr = Scommand.ExecuteNonQuery();            while(sdr.Read())
            {
               
           这的内容不知如何去写?????     我的表结构是四个字段分别为name 
                                                                                                                                                  age brithday sex

        }
    }
}
}
  谢谢大家了..........

解决方案 »

  1.   

    连的是 SQL 2005把?  你是要把数据库里的信息 输出出来吗?   是这样的
    while (sdr.Read())
    {
    System.Console.Write(sdr["name"]);
    System.Console.Write(sdr["age"]);
    System.Console.Write(sdr["brithday"]);
    System.Console.Write(sdr["sex"]);
    System.Console.WriteLine();
    }这样就可以了 
    我是小菜鸟!  说的不好清见谅,  希望能够帮到你!
      

  2.   

    SqlConnection conn = new SqlConnection("Server=localhost; Initial Catalog=stuinfo_table; User ID=sa; Password=123;"); 
            
    SqlCommand Scommand = new SqlCommand(); 
    Scommand.Connection = conn; 
    Scommand.CommandText = "select * from stuinfo_table"; conn.Open(); SqlDataReader sdr =  Scommand.ExecuteReader(); while(sdr.Read()) 

        System.Console.Write(sdr["name"]); 
        System.Console.Write(sdr["age"]); 
        System.Console.Write(sdr["brithday"]); 
        System.Console.Write(sdr["sex"]); 
        System.Console.WriteLine(); 
    }
      

  3.   

                SqlConnection conn = new SqlConnection("Server=localhost; Initial Catalog=stuinfo_table; User ID=sa; Password=123;"); 
                
                SqlCommand Scommand = new SqlCommand(); 
                Scommand.Connection=conn;
                Scommand.CommandType=CommandType.Text;
                Scommand.CommandText = "select * from stuinfo_table";             conn.Open();             SqlDataReader sdr; 
                sdr = Scommand.ExecuteReader();            while(sdr.Read()) 
                { 
                    Console.WriteLine(sdr["name"].ToString().Trim());
                    Console.WriteLine(sdr["age"].ToString().Trim());
                    Console.WriteLine(sdr["birthday"].ToString().Trim());
                    Console.WriteLine(sdr["sex"].ToString().Trim());
                }
                conn.Close();
      

  4.   

    SqlConnection conn = new SqlConnection("Server=localhost; Initial Catalog=stuinfo_table; User ID=sa; Password=123;"); 
                
                SqlCommand Scommand = new SqlCommand(); 
                Scommand.Connection=conn;
                Scommand.CommandType=CommandType.Text;
                Scommand.CommandText = "select * from stuinfo_table";             conn.Open();             SqlDataReader sdr; 
                sdr = Scommand.ExecuteReader(CommandBehavior.CloseConnection);            while(sdr.Read()) 
                { 
                    Console.WriteLine(sdr["name"].ToString().Trim());
                    Console.WriteLine(sdr["age"].ToString().Trim());
                    Console.WriteLine(sdr["birthday"].ToString().Trim());
                    Console.WriteLine(sdr["sex"].ToString().Trim());
                }
                conn.Close();