當前位置:首頁 » 編程語言 » sql連接資料庫

sql連接資料庫

發布時間: 2022-01-10 19:52:52

sql資料庫連接程序

//先申明:C# .net //可以先在web.config 中寫資料庫配置,這樣的好處是伺服器變更、資料庫名變更、密碼變更能很快修改。 <configuration> <appSettings> <add key="DbConnectionString" value="user id=sa;data source=192.168.0.2;persist security info=True;initial catalog=DataBaseName;password=" /> </appSettings> </configuration> //如果是windows應用程序,項目默認不帶配置文件,需要手動添加一個配置文件,名字是:App.config 寫法跟上面一樣。 //這樣一來,DbConnectionString就能很方便地使用了 //類中需要這兩個引用: using System.Data.SqlClient; using System.Configuration; //--連接(舉例查詢一個結果集DataSet-- string strconn= ConfigurationSettings.AppSettings["DbConnectionString"]; SqlConnection cn= new SqlConnection (strconn); SqlDataAdapter da = new SqlDataAdapter("",cn); cn.Open (); da.SelectCommand.CommandText="select * from Table1 "; DataSet ds = new DataSet(); da.Fill(ds,"Tab"); cn.Close(); //--over--

❷ 如何連接資料庫

  1. 如果您是ACCESS資料庫。這是最簡單的一種資料庫,它通常都是隨著資料庫源碼可以放在一起的,只需要知道FTP地址、賬戶與密碼就可以連接。利用FTP上傳工具上傳即可。上傳工具小編在下方資料參考處提供軟體下載鏈接。

    ❸ sql連接資料庫語句

    <%
    Set
    conn
    =
    Server.CreateObject("ADODB.Connection")
    strsql="PROVIDER=SQLOLEDB;DATA
    SOURCE=(local);UID=用戶名;PWD=密碼;DATABASE=資料庫名"
    conn.Open
    strsql
    %>

    ❹ sql資料庫連接

    看 sql手冊中文版
    http://hi..com/jayzuyw/blog/item/1d6b3a7302f5941b8701b0cb.html
    看了不知道 在來問吧

    ❺ sql怎樣連接資料庫

    .代表你連接的資料庫所是在本機上的,也可以寫成127.0.0.1\\sqlexpress
    如果你寫成別的代表你所連接的資料庫在別的電腦上,即遠程連接
    例如:server=某一電腦的
    ip(這個時候就只要寫server=ip,也可以寫成server=ip\\sqlexpress)
    希望對你有所幫助

    ❻ SQL資料庫連接語句

    <%
    Set conn = Server.CreateObject("ADODB.Connection")
    strsql="PROVIDER=SQLOLEDB;DATA SOURCE=(local);UID=用戶名;PWD=密碼;DATABASE=資料庫名"
    conn.Open strsql
    %>

    ❼ 如何連接sql資料庫即連接資料庫命令是什麼

    public SqlConnection getConn()
    {
    try
    {
    string a = AppDomain.CurrentDomain.BaseDirectory.ToString();
    string s = a.Substring(0, a.Length - 1);
    StreamReader sr = new StreamReader(s + "\\server.txt ", Encoding.GetEncoding("GB2312"));
    string ip = sr.ReadLine().Trim();
    string database = sr.ReadLine().Trim();
    string sa = sr.ReadLine().Trim();
    string pwd = sr.ReadLine().Trim();
    // conStr = "Data Source = " + ip + ";Initial Catalog = '" + s + "'; Persist Security Info = false; User ID = sa; Password = ";

    string conStr;
    conStr = "Data Source = " + ip + ";Initial Catalog = " + database + "; Persist Security Info = false; User ID = "+sa +"; Password ="+pwd +" ";

    conn = new SqlConnection(conStr);
    conn.Open();

    }
    catch (Exception es)
    { } return conn;
    }

    ❽ SQL資料庫連接查詢

    不管是1還是2都是同一個欄位cityName
    你要是這樣只能用下面的方法了
    a,b是上面的表
    select
    t1.busnum,case
    when
    t1.begincityid=1
    then
    '長春'
    ELSE
    '廣州'end
    as
    begincityid,
    case
    when
    t1.endCityId=1
    then
    '長春'
    ELSE
    '廣州'end
    as
    endCityId,t1.startTime
    from
    a
    t1,
    b
    t2
    where
    t1.begincityid=t2.cityid

    ❾ 請問Sql如何連接資料庫

    ASP的鏈接方式
    <%
    '連接資料庫
    on error resume next
    'connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("資料庫路徑") '連接ACESS
    connstr="Provider = Sqloledb; User ID =用戶名; Password =密碼; Initial Catalog = 資料庫名稱; Data Source = 資料庫地址 ;" '連接MSSQL
    set conn=server.createobject("ADODB.CONNECTION")
    conn.open connstr
    If Err Then
    response.Write "連接資料庫出錯!"
    err.Clear
    Set conn = Nothing
    Response.End
    End If
    %>
    .net的連接方式
    直接在web.config里修改

熱點內容
單片機android 發布:2024-09-20 09:07:24 瀏覽:765
如何提高三星a7安卓版本 發布:2024-09-20 08:42:35 瀏覽:664
如何更換伺服器網站 發布:2024-09-20 08:42:34 瀏覽:311
子彈演算法 發布:2024-09-20 08:41:55 瀏覽:289
手機版網易我的世界伺服器推薦 發布:2024-09-20 08:41:52 瀏覽:817
安卓x7怎麼邊打游戲邊看視頻 發布:2024-09-20 08:41:52 瀏覽:162
sql資料庫安全 發布:2024-09-20 08:31:32 瀏覽:94
蘋果連接id伺服器出錯是怎麼回事 發布:2024-09-20 08:01:07 瀏覽:507
編程鍵是什麼 發布:2024-09-20 07:52:47 瀏覽:658
學考密碼重置要求的證件是什麼 發布:2024-09-20 07:19:46 瀏覽:481