VC#数据库的连接
一、使用数据库提供程序,需引入命名空间
using System.Data.SqlClient;
二、使用数据集,需引入的命名空间
using System.Data;
三、数据库的连接
1、string connectionString="server=.;database=DBSelectCourse;integrated security=SSPI";
SqlConnection mySqlConnection=new SqlConnection(connectionString);
2、string connectionString="server=.;database=DBSelectCourse;uid=sa;pwd=sa";
SqlConnection mySqlConnection=new SqlConnection(connectionString);
四、打开和关闭数据库
mySqlConnection.Open();
mySqlConnection.Close();
五、DataSet类
DataSet myDataSet=new DataSet();
myDataSet.Tables[0].Rows[i].ItemArray[j];
六、SqlDataAdapter使用
string connectionString="server=.;database=DBSelectCourse;integrated security=SSPI";
SqlConnection mySqlConnection=new SqlConnection(connectionString);
string sqlStr="select... ...";
mySqlConnection.Open();
SqlDataAdapter mySqlDataAdapter=new SqlDataAdapter(sqlStr,mySqlConnection);
DataSet myDataSet=new DataSet();
mySqlDataAdapter.Fill(myDataSet);
mySqlConnection.Close();
七、SqlCommand类与SqlDataReader类的使用
string connectionString="server=.;database=DBSelectCourse;integrated security=SSPI";
SqlConnection mySqlConnection=new SqlConnection(connectionString);
string sqlStr="select... ...";
mySqlConnection.Open();
SqlCommand mySqlCommand=new SqlCommand(sqlStr,mySqlConnection);
SqlDataReader mySqlDataReader=mySqlCommand.ExecuteReader();
mySqlDataReader.Read();
mySqlConnection.Close();
补充:软件开发 , Vc ,