有关一点关于c# 和sql2005 之间的 连接 的 get和set!能有点例子的!就帮帮忙了啊!谢谢了!
给了高分!哈哈!谢谢了!

解决方案 »

  1.   

    什么意思??
    要写数据库的公共类吗?get和set肯定是要写属性,要想做什么东西?
      

  2.   

    是要 得到连接和设置连接吧!
    using System;
    using System.Data;
    using System.Configuration;
    using System.Data.SqlClient;/// <summary>
    /// Sql 的摘要说明
    /// </summary>
    public class Sql
    {
            private string connectionstring;
            bool state;
            public DataSet ds;
            public int count;
            private SqlConnection connect;
            public  SqlCommand command;
            private SqlDataAdapter da;
            private string tablename;
            private string commandtext;        public Sql(string str, string cmd, string table, bool st)
            {
               if(str==null)
               {
                   str="Data Source=127.0.0.1\\SQLEXPRESS;Initial Catalog=Hemis;Integrated Security=True";
               }
                commandtext = cmd;
                if (state)
                    Proc(commandtext);
                connectionstring = str;
                state = st;  
                
                tablename = table;
                connection(str);
                          
            }
           private   void connection(string con)
            {        
                connect = new SqlConnection(con);
                ds = new DataSet();
                command = connect.CreateCommand();
                command.CommandText = commandtext;
                da = new SqlDataAdapter(command);
                count = da.Fill(ds, tablename);  
            }
            private void Proc(string cmd)
            {
                command.CommandType = CommandType.StoredProcedure;
            }
        public void insert()
        {
            connect.Open();
            command.ExecuteNonQuery();
            connect.Close();
        }
      
       
    }
    要设置连接,是什么意思,你只要会
    SqlDataConnection
    SqlDataAdapter
    dataset,就可以了。
    还有SqlCommand
      

  3.   

    get和set  好像是属性,与SQL无关SQL 连接类似如下即可SqlConnection conn = new SqlConnection("Data Source=OLEDBGHHHD;Database=vv;Integrated Security=True;");
     string sql = "SELECT * FROM kkk ";   SqlDataAdapter sDa = new SqlDataAdapter(sql, conn);   DataSet ds = new DataSet();   DataTable dt = new DataTable();sDa.Fill(ds, "kkk");
      

  4.   

    我的意思就是只用  c#中的控制台应用程序 和2005sql连接的!谢谢了啊高手啊1
      

  5.   

    控制台应用程序下读出并生成图片到物理位置public void Read()
            {
                byte[] MyData = new byte[0];
                using (SqlConnection conn = new SqlConnection(sqlconnstr))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    cmd.CommandText = "select * from T_img";
                    SqlDataReader sdr = cmd.ExecuteReader();
                    sdr.Read();
                    MyData = (byte[])sdr["ImgFile"];//读取第一个图片的位流
                    int ArraySize= MyData.GetUpperBound(0);//获得数据库中存储的位流数组的维度上限,用作读取流的上限                FileStream fs = new FileStream(@"c:\00.jpg", FileMode.OpenOrCreate, FileAccess.Write);
                    fs.Write(MyData, 0, ArraySize);
                    fs.Close();   //-- 写入到c:\00.jpg。
                    conn.Close();
                    Console.WriteLine("读取成功");//查看硬盘上的文件
                }
            }
      

  6.   

    get,set 是属性
     2005数据库连接
     
      SQLCONNECTION SQLCON=NEW SQLCONNECTION("SERVER=.\SQLEXPRESS;DATABASE='数据库名';Integrated Security=True");//WINDOWS登陆方式
      SQLCONNECTION SQLCON=NEW SQLCONNECTION("SERVER=.\SQLEXPRESS;DATABASE='数据库名';Uid='';Pwd=");//用户登陆方式
      

  7.   

    在web.config内添加如下
             <connectionStrings>
    <add name="一个名" connectionString="data source=(local); initial catalog=数据库名;integrated security=sspi"/>
       </connectionStrings>
    在.cs中写
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["一个名"].ToString();
    便可以连上你要连的数据库
      

  8.   

    没听懂你是要问什么,若是想了解GET和SET,去MSDN上瞧一下,那会有详细解释的
      

  9.   

    SqlConnection con = new SqlConnection("连接字符串")
    con.Open();...
    .
    .
    .
    ...
    con.Close();