怎么在textbox里面输入用户名,点击查询后,在datagridview里面把它输出来

Amlyuu 2017-06-05 06:41:22



string str = textBox1.Text;
SqlConnection mycon = getConnection();
mycon.Open();
string sql = "select * from customers where joinid='" + textBox1.Text + "'";
SqlCommand mycom = new SqlCommand(sql, mycon);
SqlDataReader mydr = mycom.ExecuteReader();
if (mydr.Read())
{

}
...全文
146 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wang_peng_yl 2017-06-06
  • 打赏
  • 举报
回复
引用 2 楼 duanzi_peng 的回复:
根据sql语句用sqldataadapter填充数据到datatable,再赋值给dgv的Datasource。
建议版主们对于这些初学者,尽量写细节
wang_peng_yl 2017-06-06
  • 打赏
  • 举报
回复
string str = textBox1.Text; SqlConnection mycon = getConnection(); mycon.Open(); string sql = "select * from customers where joinid='" + textBox1.Text + "'"; SqlDataAdapter da = new SqlDataAdapter(sql, mycon); DataTable dt = new DataTable(); da.Fill(dt); this.dataGridView1.DataSource = dt;
Amlyuu 2017-06-05
  • 打赏
  • 举报
回复
引用 2楼exception11 的回复:
根据sql语句用sqldataadapter填充数据到datatable,再赋值给dgv的Datasource。
是在if(madr.read())里面写吗
  • 打赏
  • 举报
回复
根据sql语句用sqldataadapter填充数据到datatable,再赋值给dgv的Datasource。
Amlyuu 2017-06-05
  • 打赏
  • 举报
回复
getConnection是我写的一个连接类 private SqlConnection getConnection() { string constr = "Server=.;user=sa;pwd=sql19980215;database=bankall"; SqlConnection mycon = new SqlConnection(constr); return mycon; }

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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