datagridview显示数据库内容出错

龙在江湖aa 龙在江湖aa 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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("姓名有误!请重新输入!"); }
}
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
龙在江湖aa
C# 111,129 成员 642,540 内容