C# asp.net Sql2000 UML 学习分享ing......

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

c#控制台 使用sdr读取sql数据,

 1using System;
 2using System.Collections.Generic;
 3using System.Text;
 4using System.Data.SqlClient;
 5
 6namespace ConsoleApplication_proc
 7{
 8    class sdr_proc
 9    {
10        static void Main(string[] args)
11        {
12            SqlConnection con = myconnection.getSqlConnection();
13            con.Open();
14            SqlCommand cmd = new SqlCommand("select * from photo", con);
15            SqlDataReader sdr = cmd.ExecuteReader();
16            while (sdr.Read())
17            {
18
19                Console.WriteLine(sdr["id"+ "____  __ ________" + sdr["photoname"]);
20
21
22
23                //Console.WriteLine("你刚才输入的是{0}",s);
24
25            }

26
27            sdr.Close();
28            con.Close();
29            Console.Read();
30
31            //string k = Console.ReadLine();
32            //Console.WriteLine("你刚才输入的是{0}", k);
33            //Console.ReadLine();
34
35
36            ////Console.ReadLine()的方法
37            //Console.Write("请输入你的姓名:");//Console.Write()方法是不换行输出信息
38            //string s = Console.ReadLine();
39            ////此方法是读取输入的名字并把它存入到字符串s中;
40            //Console.WriteLine("Hi,{0}.Welcome", s);//Console.WriteLine()是先输出信息再换行
41            ////Console.read()方法
42            //Console.Write("请输入你的生日:");
43            //int i = Console.Read();
44            //Console.Write("您的生日是:{0}!", i);
45
46
47                            //           
48                            //  可以Console.Write写字符, 
49                            //Console.WriteLine 写一行字符 
50                            //Console.Read 读字符 
51                            //Console.ReadLine 读取一行字符  
52                            //            // 
53
54            int  a = Console.Read();
55            Console.WriteLine("你的生日@是:{0}",a);
56            Console.Read();
57            Console.ReadLine();
58        
59           
60        }

61    }

62}

63


 1using System;
 2using System.Collections.Generic;
 3using System.Text;
 4using System.Data.SqlClient;
 5
 6namespace ConsoleApplication_proc
 7{
 8    class myconnection
 9    {
10       public static SqlConnection getSqlConnection()
11       {
12           return new SqlConnection("server=.;uid=sa;database=stu;pwd=");
13       }

14    }

15    
16}

17


posted on 2007-03-25 14:26  2007—2008C#年  阅读(1488)  评论(0)    收藏  举报