1.c#连接数据库
要用到VS2008哪里空间定义呀..(using system...)????
2.为什么我看到一些网上直接用MySqlConnection  或许 SqlConnetion 还有一些的连接数据库..到底是用哪种方法呀..我用的VS2008是用MySqlConnection可是为什么有的是用SqlConnection???3.还有用C#连接各种数据方法有哪有呀???

解决方案 »

  1.   

    using System.Data.SqlClient.SqlConnection;
      

  2.   

    http://www.connectionstrings.com/
      

  3.   

    SqlConnetion 是MSSQL专用的连接数据库的类,其他的一般是用OLEDBConnection吧!反正我一直是用SqlConnection。
      

  4.   

    引用using System.Data;
    using System.Data.SqlClient;连接字符串
    DbConnection
    数据库连接类
    OdbcConnection类 
    OleDbConnection类
    OracleConnection类
    SqlConnection类Ado.net分为数据连接模式和断开模式
    Sqlserver的连接类是SqlConnection,命令类是SqlCommand,数据阅读类是SqlDataReader
      

  5.   

    1.c#连接数据库 
    要用到VS2008哪里空间定义呀..(using system...)????
    看你连接什么数据库,如果是SqlServier,那么就using System.Data.SqlClient,如果是Access,就可以using System.Data.OleDb。一个小小的建议,你可以采用Microsoft Patterns and Practice里的Data Access Application Block来做数据库操作,简单而且“跨数据库”
     
    2.为什么我看到一些网上直接用MySqlConnection  或许 SqlConnetion 还有一些的连接数据库..到底是用哪种方法呀..我用的VS2008是用MySqlConnection可是为什么有的是用SqlConnection??? 
    网上直接用,是因为它使用了第三方的MySql数据库支持库,在它的项目的“引用”部分直接引用了MySql相关的程序集,那么在使用的时候,就直接using了。这跟SQLite类似。因为你没有使用这个支持库,所以你没有办法using MySql。3.还有用C#连接各种数据方法有哪有呀???
    目前VS支持SQLServier,Oracle和Access等,你可以使用上面我提到的Data Access Application Block,也可以用NHibernate(当然NHibernate的真正意义不在于此),当然,还有第三方的data provider,比如你上面说的MySqlConnection以及SQLite。
      

  6.   

    数据库详细连接如下:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using System.Windows.Forms;namespace PWMS.DataClass
    {
        class MyMeans
        {
            #region 全局变量
            public static string Logion_ID = ""; //记录全局变量。记录当前登陆的用户编号
            public static string Logion_Name = "";//定义全局变量,记录当前登陆的用户名
             
            //定义静态全局变量,记录“基础信息”各窗体中的表名、SQL语句以及要添加和修改的字段名
            public static string Mean_SQL = "", Mean_Table = "", Mean_Field = "";
            //定义一个SqlConnection类型的静态公共变量My_con,用于判断数据库是否成功连接
            public static SqlConnection My_con;
            //定义SQL SERVER2005连接字符串,用户在使用时,将Data Source改为自己的SQL SERVER2005服务器名。
            public static string M_str_sqlcon = "Data Source=localhost;Database=db_PWMS;Uid=sa;PWD=''";
            public static int Login_n =0;// 用户登陆与重新登陆的标示
            public static string ALLSql="Select * from tbStuffbusic";
            #endregion        #region 数据库连接
            public static SqlConnection getcon()
            {
                My_con = new SqlConnection(M_str_sqlcon);
                My_con.Open();
                return My_con;
            }
            #endregion        #region 关闭数据库
            public void con_close()
            {
                if (My_con.State == ConnectionState.Open)
                {
                    My_con.Close();
                    My_con.Dispose();    
                }
            }
            #endregion        #region 以只读方式传入SQL语句
            public SqlDataReader getcom(string SQLstr)
            {
                getcon();
                SqlCommand My_com=My_con.CreateCommand();
                My_com.CommandText = SQLstr;
                SqlDataReader My_read = My_com.ExecuteReader();
                return My_read;
            }
            #endregion        #region  执行数据库的修改和增加
            public void getsqlcom(string SQLstr)
            {
                getcon();
                SqlCommand SQLcom = new SqlCommand(SQLstr, My_con);
                SQLcom.ExecuteNonQuery();
                SQLcom.Dispose();
                con_close();
            }
            #endregion        #region 执行数据库的增加和修改
            public DataSet getDataSet(string SQLstr, string tableName)
            {
                getcon();
                SqlDataAdapter SQLda = new SqlDataAdapter(SQLstr, My_con);
                DataSet My_Dataset = new DataSet();
                SQLda.Fill(My_Dataset, tableName);
                con_close();
                return My_Dataset;
            }
            #endregion
        }
    }我已经连接成功,如果有朋友没有成成功,请联系我。QQ:380699258
      

  7.   

            Data Source=.\SQLEXPRESS;Integrated Security=True;Connect Timeout=30;Password=123456;User ID=sa;DataBase=lfcars; 这是Codesmith链接字符串         ASP 中通过 OLE DB 接口方式连接 Microsoft SQL Server 2000 和 Microsoft SQL Server 2005 ,连接字符串有一点区别,主要就是 Provider 后的内容。Microsoft SQL Server 2000        Provider=SQLOLEDB;Data Source=server;Initial Catalog=database;User Id=user;Password=password;或者       Provider=SQLOLEDB;Server=server;Database=database;Uid=user;Pwd=password;Microsoft SQL Server 2005        Provider=SQLNCLI;Data Source=server;Initial Catalog=database;User Id=user;Password=password;或者        Provider=SQLNCLI;Server=server;Database=database;Uid=user;Pwd=password;        确认你使用了TCP/IP协议,允许远程连接总结sql 2005:        确认你使用了TCP/IP协议,允许远程连接        Driver={SQL   Native   Client};   
            Server=主机名\SQLEXPRESS;   
            Database=数据库;   
            UID=sa;   //真正的用户名
            PWD=123;//密码
      

  8.   

    我使用的Oracle数据库,
    就我所知,连接Oracle有三种方式,
    1、OLE
    2、ODBC
    3、ODP其中ODBC和ODP都可以使用不同的驱动,分别由Oracle和Microsoft提供。
      

  9.   

    using System.Data.SqlClient;命名空间
    Sqlconnecting,自动提示的
    给你发个例子吧
    protected void Button1_Click(object sender, EventArgs e)
        {
            if (RadioButton1.Checked)
            {
                SqlConnection con;
                con = new SqlConnection("Data Source=192.168.0.108;Initial Catalog=LFCHA;User ID=sa;pwd=123");
                string strSql, strsql1;
                strSql = "Select * From Salesperson Where ID='" + TextBox1.Text.ToString().Trim() + "' And Password='" + TextBox2.Text.ToString().Trim() + "'";
                strsql1 = "Select * From Salesperson Where ID='" + TextBox1.Text.ToString().Trim() + "'";
                SqlCommand sqlcomd = new SqlCommand(strSql, con);
                SqlCommand sqlcomd1 = new SqlCommand(strsql1, con);
                con.Open();
                SqlDataReader dr = sqlcomd.ExecuteReader();
                if ((dr.Read() == true))
                {
                    Session["sina"] = TextBox1.Text.ToString().Trim();
                    Session["password"] = TextBox2.Text.ToString().Trim();
                    con.Close();
                    FormsAuthentication.SetAuthCookie(TextBox1.Text, false);
                    Response.Redirect("SalespersonQuery.aspx");
                    Response.End();
                }
                con.Close();
                con.Open();
                SqlDataReader dr1 = sqlcomd1.ExecuteReader();
                if (dr1.Read() == true)
                {
                    Label3.Text = "密码错误";
                    con.Close();
                }
                else
                {
                    con.Close();
                    Label3.Text = "帐户错误";
                }
           }
           if (RadioButton2.Checked)
           {
               SqlConnection con;
               con = new SqlConnection("Data Source=192.168.0.108;Initial Catalog=LFCHA;User ID=sa;pwd=123");
               string strSql, strsql1;
               strSql = "Select * From Manager Where ID='" + TextBox1.Text.ToString().Trim() + "' And Password='" + TextBox2.Text.ToString().Trim() + "'";
               strsql1 = "Select * From Manager Where ID='" + TextBox1.Text.ToString().Trim() + "'";
               SqlCommand sqlcomd = new SqlCommand(strSql, con);
               SqlCommand sqlcomd1 = new SqlCommand(strsql1, con);
               con.Open();
               SqlDataReader dr = sqlcomd.ExecuteReader();
               if ((dr.Read() == true))
               {
                   Session["sina"] = TextBox1.Text.ToString().Trim();
                   Session["password"] = TextBox2.Text.ToString().Trim();
                   con.Close();
                   FormsAuthentication.SetAuthCookie(TextBox1.Text, false);
                   Response.Redirect("ManagerQuery.aspx");
                   Response.End();
               }
               con.Close();
               con.Open();
               SqlDataReader dr1 = sqlcomd1.ExecuteReader();
               if (dr1.Read() == true)
               {
                   Label3.Text = "密码错误";
                   con.Close();
               }
               else
               {
                   con.Close();
                   Label3.Text = "帐户错误";
               }
           }
      

  10.   

    using System.Data.SqlClient;
      

  11.   

    using System.Data; 
    using System.Data.SqlClient;