各位大神帮帮忙吧 看看哪里错了

qq_41504478 2017-12-23 10:26:43
string constr = @"Data Source=.; Initial Catalog=liunian; Integrated Security=True";
string sql = "select * from studentInflo where studentNumber ='"+ textBox1.Text + "'";
MessageBox.Show(sql);
SqlParameter aaa = new SqlParameter("@id", textBox1.Text);
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(sql, con))
{
cmd.Parameters.Add(aaa);
con.Open();
using (SqlDataReader rdr = cmd.ExecuteReader())
{
textBox2.Text = null;
while (rdr.Read())
{
for (int i = 0; i < rdr.FieldCount; i++)
{
textBox2.AppendText(rdr[i].ToString());
}
textBox2.AppendText("\r\n");
}
}
}
}
...全文
376 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
轻鸿万里 2017-12-28
  • 打赏
  • 举报
回复
string constr = @"Data Source=.; Initial Catalog=liunian; Integrated Security=True"; string sql = "select * from studentInflo where studentNumber ='"+ textBox1.Text + "'"; MessageBox.Show(sql); using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(sql, con)) { con.Open(); using (SqlDataReader rdr = cmd.ExecuteReader()) { textBox2.Text = null; while (rdr.Read()) { for (int i = 0; i < rdr.FieldCount; i++) { textBox2.AppendText(rdr[i].ToString()); } textBox2.AppendText("\r\n"); } } } } 你干脆改成这样
圣殿骑士18 2017-12-23
  • 打赏
  • 举报
回复
你既然用了SqlParameter 就不应该是 string sql = "select * from studentInflo where studentNumber ='"+ textBox1.Text + "'"; 而是 string sql = "select * from studentInflo where studentNumber =@id";
threenewbee 2017-12-23
  • 打赏
  • 举报
回复
报什么错?数据库连上了么?查询写对了么?

16,552

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧