大家好啊,我要是想用C#连SQL SERVER 数据库我要怎么样做的啊,我连过ACCESS的数据库, 可以连到SQL的时候就有点问题,请大家给帮帮我吧。

解决方案 »

  1.   

    public void InsertRow(string myConnectionString) 
     {
        // If the connection string is null, use a default.
        if(myConnectionString == "") 
        {
           myConnectionString = "Initial Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI;";
        }
        SqlConnection myConnection = new SqlConnection(myConnectionString);
        string myInsertQuery = "INSERT INTO Customers (CustomerID, CompanyName) Values('NWIND', 'Northwind Traders')";
        SqlCommand myCommand = new SqlCommand(myInsertQuery);
        myCommand.Connection = myConnection;
        myConnection.Open();
        myCommand.ExecuteNonQuery();
        myCommand.Connection.Close();
     }
      

  2.   

    myConnectionString = (server=(local);database=数据名;uid=sa;pwd=)