China Manufacturing Trading Network
Steps for connecting to the database:
1. Create a sqlconnection object;
2. Specify the connectionstring attribute of the sqlconnection object;
3. Open the database connection;
4. Specify an SQL statement;
5. Create a sqldataadapter object and a DataSet object (mydataadapter = new sqldataadapter (strcmd, Conn );
);
6. Add a dataset;
7. Specify a data source for the DataGrid
Sqlconnection conn = new sqlconnection ();
Conn. connectionstring = "Data Source = (local); initial catalog = test; user id = sa; Password = sa ";
Conn. open ();
String strcmd;
Strcmd = "select * from test ";
Sqldataadapter mydataadapter;
Dataset mydataset = new dataset ();
Mydataadapter = new sqldataadapter (strcmd, Conn );
Mydataadapter. Fill (mydataset, "test ");
Mytestdatagrid. datasource = mydataset. Tables ["test"];
Note: The database is installed locally. The database name is test, the user name is SA, and the password is Sa;
The table in the database is test;