c#调用 SQL SERVER

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Windows;  
using System.Windows.Forms;  
using System.Drawing;  
using System.IO;  
using System.Collections;  
using System.Configuration;  
using System.Data;
using System.Data.SqlClient;

    class Program
    {
        static void Main(string[] args)
        {
            string coonString = "server=192.168.30.10;database=ykhc;uid=sa;pwd=hc2008";
            SqlConnection conn = new SqlConnection(coonString);
            SqlCommand cmd = conn.CreateCommand();
            //sql语句     
            cmd.CommandText = "SELECT goodsname, Basebarcode, saleprice, categorycode from \"000\".tbgoods";
            //打开连接     
            conn.Open();
            //执行sql     
            //cmd.ExecuteNonQuery();     
            //若要创建 SqlDataReader,必须调用 SqlCommand 对象的 ExecuteReader 方法,而不要直接使用构造函数   
            SqlDataReader dr =  cmd.ExecuteReader();

            while (dr.Read())
            {
                Console.Write(dr[0] + "\t");
                Console.Write(dr[1] + "\t");
                Console.Write(dr[2] + "\t");
                Console.Write(dr[3]);
                Console.WriteLine();
            }
            dr.Dispose();
            //关闭连接     
            conn.Close();

        }
    }

阅读更多
上一篇Windows 部署 tomcat 实现下载功能
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭