OdbcConnection nwindConn = new OdbcConnection("Driver={SQL Server};Server=localhost;" +
                                              "Trusted_Connection=yes;Database=northwind");
nwindConn.Open();

解决方案 »

  1.   

    public void InsertRow(string myConnection) 
    {
       // If the connection string is null, use a default.
       if(myConnection == "") 
       {
          myConnection = "DRIVER={SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;";
       }
       OdbcConnection myConn = new OdbcConnection(myConnection);
       string myInsertQuery = "INSERT INTO Customers (CustomerID, CompanyName) Values('NWIND', 'Northwind Traders')";
       OdbcCommand myOdbcCommand = new OdbcCommand(myInsertQuery);
       myOdbcCommand.Connection = myConn;
       myConn.Open();
       myOdbcCommand.ExecuteNonQuery();
       myOdbcCommand.Connection.Close();
    }