c#数据库简单操作

来源:互联网 发布:闲鱼怎样申请淘宝介入 编辑:程序博客网 时间:2024/05/21 07:01
      
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data.SqlClient; namespace AccessDb{    class Program    {        static void Main(string[] args)        {              String connectionStr = @"server=ip;database=daqing2_91_hd_Info;uid=sa;pwd=密码";              SqlConnection connection = new SqlConnection(connectionStr);              connection.Open();               String SQLCOMMAND = "SELECT * FROM   BeautyInfo";               SqlCommand command = new SqlCommand(SQLCOMMAND, connection);               SqlDataReader reader = command.ExecuteReader();                            int colNum = reader.FieldCount;              while (reader.Read())              {                  for (int i = 0; i < colNum; i++)                  {                      Console.WriteLine(reader[i]);                  }              }               if (connection != null)              {                  connection.Close();              }               Console.ReadLine();        }    }}
0 0
原创粉丝点击