你试试用工具箱里面的SQLCONNECTION和SQLCOMMANDSQLCONNECTION可以以向导模式让你连接数据库

解决方案 »

  1.   

    conn=new SqlConnection("Data Source=XUEXUEGO-NRHZVJ;initial Catalog=mypage;User id=sa;Pwd=811215);
    换成
    conn = "Data Source=.;integrated security=SSPI;Connection Timeout = 5;user id=sa;password=811215;initial catalog=mypage;";
    看看
      

  2.   

    sub.Apped("VALUES('{1}','{2}','{3}')");
    改成sub.Append("VALUES('{0}','{1}','{2}')");
    还有values.Add(0);是什么意思
      

  3.   

    有必要自己写这么详细的代码吗?用.Net提供的向导去建立连接不是很方便吗?
      

  4.   

    呵呵,是啊,很容易的么。就是你添加一个SQLCONNECTION,然后配置链接字串就好了啊。
      

  5.   

    不好意思,是我的不对,没仔细看。你的是web form,没什么了解。我rollback上面的word
      

  6.   

    conn=new SqlConnection("Data Source=XUEXUEGO-NRHZVJ;initial Catalog=mypage;User id=sa;Pwd=811215);应该是
    conn=new SqlConnection("Data Source=XUEXUEGO-NRHZVJ;initial Catalog=mypage;User id=sa;Pwd=811215");
      

  7.   

    http://www.connectionstrings.com/ ODBC 
     Standard Security:"Driver={SQL Server};Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd;"  Trusted connection:"Driver={SQL Server};Server=Aron1;Database=pubs;Trusted_Connection=yes;"  Prompt for username and password:oConn.Properties("Prompt") = adPromptAlways
    oConn.Open "Driver={SQL Server};Server=Aron1;DataBase=pubs;"  OLE DB, OleDbConnection (.NET) 
     Standard Security:"Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;"  Trusted Connection:"Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;" 
    (use serverName\instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)
     Prompt for username and password:oConn.Provider = "sqloledb"
    oConn.Properties("Prompt") = adPromptAlways
    oConn.Open "Data Source=Aron1;Initial Catalog=pubs;"  Connect via an IP address:"Provider=sqloledb;Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;" 
    (DBMSSOCN=TCP/IP instead of Named Pipes, at the end of the Data Source is the port to use (1433 is the default))
     SqlConnection (.NET) 
     Standard Security:"Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;" 
       - or -
    "Server=Aron1;Database=pubs;User ID=sa;Password=asdasd;Trusted_Connection=False" 
       (booth connection strings produces the same result)
     Trusted Connection:"Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;" 
       - or -
    "Server=Aron1;Database=pubs;Trusted_Connection=True;" 
       (booth connection strings produces the same result)(use serverName\instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)
     Connect via an IP address:"Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;" 
    (DBMSSOCN=TCP/IP instead of Named Pipes, at the end of the Data Source is the port to use (1433 is the default))
     Declare the SqlConnection:C#:
    using System.Data.SqlClient;
    SqlConnection oSQLConn = new SqlConnection();
    oSQLConn.ConnectionString="my connectionstring";
    oSQLConn.Open(); VB.NET:
    Imports System.Data.SqlClient
    Dim oSQLConn As SqlConnection = New SqlConnection()
    oSQLConn.ConnectionString="my connectionstring"
    oSQLConn.Open()