datagridview显示数据库内容出错
if (comboBox1.Text == "编号")
{
string id = textBox3.Text;
String sql2 = String.Format("select * from T_book where book_id= '{0}'", id);
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql2, conn);
SqlCommand command = new SqlCommand(sql2, conn);
int num = Convert.ToInt32(command.ExecuteScalar());
if (num > 0)
{
DataSet ds = new DataSet();
sda.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
else { MessageBox.Show("姓名有误!请重新输入!"); }
}
if (comboBox1.Text == "书名")
{
string book_name = textBox3.Text;
String sql2 = String.Format("select * from T_book where book_name= '{0}'", book_name);
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql2, conn);
SqlCommand command = new SqlCommand(sql2, conn);
int num = Convert.ToInt32(command.ExecuteScalar());
if (num > 0)
{
DataSet ds = new DataSet();
sda.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
else { MessageBox.Show("姓名有误!请重新输入!"); }
}
{
string id = textBox3.Text;
String sql2 = String.Format("select * from T_book where book_id= '{0}'", id);
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql2, conn);
SqlCommand command = new SqlCommand(sql2, conn);
int num = Convert.ToInt32(command.ExecuteScalar());
if (num > 0)
{
DataSet ds = new DataSet();
sda.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
else { MessageBox.Show("姓名有误!请重新输入!"); }
}
if (comboBox1.Text == "书名")
{
string book_name = textBox3.Text;
String sql2 = String.Format("select * from T_book where book_name= '{0}'", book_name);
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql2, conn);
SqlCommand command = new SqlCommand(sql2, conn);
int num = Convert.ToInt32(command.ExecuteScalar());
if (num > 0)
{
DataSet ds = new DataSet();
sda.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
else { MessageBox.Show("姓名有误!请重新输入!"); }
}
...全文
相关推荐
C#访问SQL显示到DataGridView,同时根据DataGridView实时更新数据库
C#实现将SQL数据库的内容读取出来显示到DataGridview中,同时根据DataGridview更新数据库内容
将datagridview内容直接更新到ACCESS数据库中
将datagridview内容直接更新到ACCESS数据库中
C#使用DataGridView显示Excel内容
C#使用DataGridView绑定Excel,然后让用户选择Excel文件的工作表,然后点击DataGridView显示按钮就能绑定选定的工作表。 写这个主要是为了答疑CSDN论坛上一些朋友的疑问,他们想绑定Excel文件,而有不知道工作表的名字。 使用了OFFICE2007连接字符串,如果使用office2003的请更改连接字符串为:Provider=Microsoft.JET.OLEDB.4.0;.........;Extended Properties='Excel 12.0;HDR=NO;IMEX=1' 即可
c# 如何删除datagridview中数据并删除数据库中的数据
删除datagridview中数据并删除数据库中的数据,删除完了重新绑定一次
DataGridView中数据存入数据库方法
DataGridView中数据存入数据库方法


