C# 添加记录时无法找到表0是怎么回事

来源:百度知道 编辑:UC知道 时间:2024/06/24 23:40:01
Class1 mycls = new Class1();
string str = "insert into 学委通讯录 (班级) values ('" + this.textBox2.Text + "')";
mycls.updata(str);
string newstr = "select * from 学委通讯录";
mycls.getdata(newstr);
this.dataGrid1.DataSource = mycls.myDs.Tables[0];
我是一个初学者,请指点

把这句代码改为:

this.dataGrid1.DataSource = mycls.myDs.Tables["学委通讯录"];试一下

上面的说得很对:最好不要用中文数据库名或是表名。

这个0的位置应该是数据库名称,你写错了,改成"学委通讯录"

给你一个忠告,表名用英文