C#连接数据库中一些关键字的使用

关键字的说明

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”);

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值