dataGridView 控件查询显示代码??(急!!!)

mengsuifengfei 2010-01-31 08:34:55
我想实现查询显示功能,代码一部分在下面,那位大虾给添加完啊!!谢谢了 ~~~





private void button1_Click(object sender, EventArgs e)
{
// string phone, username, sex, job, Email, grouping;
DbType type = DbType.String;
string cx1,cx2;
cx1 = cxtj1.Text;
cx2 = cxtj2.Text;
try
{
switch (cx1)
{

case "":
MessageBox.Show("请输入查询条件!", "友情提示o(∩_∩)o...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
case "姓名":
break;
case "性别":
haha = new SqlDataAdapter("select * from 性别 where sex", cn);
haha.Fill(heihei, "tongxunbo");
xsk.DataSource = heihei.Tables["tongxunbo"];
break;
case "电话":
break;
case "城市":
break;
case "查找所有联系人":
//显示所有联系人信息
haha = new SqlDataAdapter("select * from tongxunbo", cn);
haha.Fill(heihei, "tongxunbo");
xsk.DataSource = heihei.Tables["tongxunbo"];
break;
}
}
...全文
82 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
happyboyxq1985 2010-02-01
  • 打赏
  • 举报
回复
private void button1_Click(object sender, EventArgs e)
{
// string phone, username, sex, job, Email, grouping;
DbType type = DbType.String;
string cx1,cx2;
cx1 = cxtj1.Text;
cx2 = cxtj2.Text;
try
{
switch (cx1)
{

case "":
MessageBox.Show("请输入查询条件!", "友情提示o(∩_∩)o...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
case "姓名":
break;
case "性别":
haha = new SqlDataAdapter("select * from 性别 where sex", cn);
haha.Fill(heihei, "tongxunbo");
xsk.DataSource = heihei.Tables["tongxunbo"].Defaultvalue;
break;
case "电话":
break;
case "城市":
break;
case "查找所有联系人":
//显示所有联系人信息
haha = new SqlDataAdapter("select * from tongxunbo", cn);
haha.Fill(heihei, "tongxunbo");
xsk.DataSource = heihei.Tables["tongxunbo"].Defaultvalue;
break;
}
}


加上Defaultvalue属性是很重要的,不然dataGridView的数据源虽然绑定了,但是仍然无法刷新显示。
小在在 2010-01-31
  • 打赏
  • 举报
回复
private void button1_Click(object sender, EventArgs e)
{
// string phone, username, sex, job, Email, grouping;
DbType type = DbType.String;
string cx1,cx2;
cx1 = cxtj1.Text;
cx2 = cxtj2.Text;
try
{
switch (cx1)
{

case "":
MessageBox.Show("请输入查询条件!", "友情提示o(∩_∩)o...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
case "姓名":
break;
case "性别":
//-----------------------------
SqlConnection cn = new SqlConnection("Server=localhost;uid=sa;pwd=;Database=数据库名字");
cn.Open();

//-------------------------------

haha = new SqlDataAdapter("select * from 性别 where sex", cn);
haha.Fill(heihei, "tongxunbo");
xsk.DataSource = heihei.Tables["tongxunbo"];
break;
case "电话":
break;
case "城市":
break;
case "查找所有联系人":
//显示所有联系人信息
//-----------------------------
SqlConnection cn = new SqlConnection("Server=localhost;uid=sa;pwd=;Database=数据库名字");
cn.Open();

//-------------------------------
haha = new SqlDataAdapter("select * from tongxunbo", cn);
haha.Fill(heihei, "tongxunbo");
xsk.DataSource = heihei.Tables["tongxunbo"];
break;
}
}
KnowKjava 2010-01-31
  • 打赏
  • 举报
回复
dataGridView

110,561

社区成员

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

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

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