菜鸟问题,如何将数据库里面的数据显示到Textbox?
问题很菜,就是想实现一个简单的对数据库(access)进行查询、插入、删除、修改等操作的小winform程序。现在问题就是如何将数据库里面的数据显示到Textbox?
就是点击查询按钮的时候查询的数据显示到各对应的Textbox。
插入删除都没有问题。oledbadapter和dataset都是通过控件拖放完成的,数据绑定也是。是不是要借助datagridview?
下面是添加按钮的一点代码:
private void addbtn_Click(object sender, EventArgs e)
{
try
{
oleDbInsertCommand1.CommandText = "insert into [user] (empName,tyDepart,tymanagers,tycommercer,CornID,RiceID) values( ' " + NameBox.Text + " ', ' " + DepartcomboBox1.SelectedItem + " ', ' " + managebtn.Checked + " ', ' " + commercerbtn.Checked + " ', ' " + CornBox.Text + " ', ' " + RiceBox.Text + " ') ";
oleDbConnection1.Open();
oleDbInsertCommand1.ExecuteNonQuery();
oleDbSelectCommand1.CommandText = "select count(*) from [user] where empName= ' " + NameBox.Text + " ' ";
string NumCount = oleDbSelectCommand1.ExecuteScalar().ToString();
if (NumCount == "1 ")
{
MessageBox.Show( "成功添加员工! ", "成功 ", System.Windows.Forms.MessageBoxButtons.OK);
}
else
{
MessageBox.Show( "添加失败! ", "失败 ",System.Windows.Forms.MessageBoxButtons.OK);
}
oleDbConnection1.Close();