Thread: C# основной форум/Connection to database

Connection to database
SqlConnection SQLCon = new SqlConnection("ConnectionString");
SQLCon.Open();

SqlCommand SQLCom = new SqlCommand();
SQLCom.CommandText = "SELECT * from mytable";
SQLCom.Connection = SQLCon;

SqlDataAdapter SQLAdap = new SqlDataAdapter();
SQLAdap.SelectCommand = SQLCom;

DataSet1.MyTable.Clear();
SQLAdap.Fill(DataSet1.MyTable);



string strConnectionString = "server=localhost;database=pubs;user id=pubs;password=pubs;";
//  string strConnectionString = "server=localhost;database=pubs;user=pubs;PWD=pubs;";
            SqlConnection myConnection = new SqlConnection(strConnectionString);
            myConnection.Open();

            SqlCommand mySQL = new SqlCommand();
            mySQL.CommandText = "select * from authors";
            mySQL.Connection = myConnection;
            mySQL.CommandType = CommandType.Text;

            SqlDataAdapter mySQLDataAdapter = new SqlDataAdapter();
            mySQLDataAdapter.SelectCommand = mySQL;

            DataSet myDataSet = new DataSet();

            mySQLDataAdapter.Fill(myDataSet, "authors");

            dataGridView1.DataSource = myDataSet;
            dataGridView1.DataMember = "authors";


            myConnection.Close();
            myConnection.Dispose() ;
            mySQLDataAdapter.Dispose();