关键字的说明
DataSet–建立当期虚拟的数据库
DataTable–建立前台虚拟数据库的表
DataRowCollection–相当于表的集合
DataRow–相当于表达列的集合
MysqlDataAdapter–数据适配器,用于从数据库中读取数据
关键字的实际使用
DataSet ds=new DataSet();
DataTable db=new DataTable();
DataTable dtableStudenyInfo;
DataRowCollection TableRow;//数据库的行的集合
DataRow TableColumn;//相当于表的列
string sltstr=“select id,username,userid from student_info;”;//查询字符串
MySqlCommand MysqlCmd=new MySqlCommand(sltstr,MySqlCon);
MySqlDataAdapter Msda=new MySqlDataAdapter(MysqlCmd);
Msda.Fill(Ds,“StudentInfoi”);//将查询结果存到虚拟数据库Ds中的虚拟表StudentInfo中
DtableStudentInfo=Ds.Tables[“StudentInfo”]//将数据表StudentInfo的数据复制到Datatable对象中
TableRow=DtableStudnetInfo.Rows;//用DataRowCollection对象获取这个表中所有数据行
string infoString=" ";
//逐行遍历取出每行数据
for(int i=0;i<TableRow.Count;i++)
{
TableColumn=TableRow[i];//表示第几行的数据
infoString+="id: "+TableColumn[0];//数据的第几列
infoString+="username "+TableColumn[1];
infoString+=“userid “+TableColumn[2]+”\n”;
}
Console.Writeline(infostring);
MysqlCon.close();
更新数据库
for(int i=0;i<TableRow.Count;i++)
{
TableColumn=TableRow[i];
if(drow[“id”].Tostring==1+" ")
{
drow[“password”]=“123321”;
}
}
//更新数据库
msda.Update(ds,“StudentInfoi”);