| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 815 人关注过本帖
标题:windows应用程序DataReader的综合应用事例
只看楼主 加入收藏
王杰
Rank: 2
等 级:新手上路
威 望:4
帖 子:307
专家分:0
注 册:2005-5-13
收藏
 问题点数:0 回复次数:0 
windows应用程序DataReader的综合应用事例

一日群里有人问window下textbox如何单独绑定数据库中的某个字段,起初我也不是很懂,但略微思考一下还是实现了,由于论坛字数限制,略掉部分代码,部分主要代码及图片如下(图片保存在附件中):
private void button8_Click(object sender, System.EventArgs e)
{
this.Close();
}

private void Form2_Load(object sender, System.EventArgs e)
{
System.Data.SqlClient.SqlDataReader dr=d();
if (dr.Read())
{
textBox1.Text=dr["编号"].ToString();
textBox2.Text=dr["民族"].ToString();
textBox3.Text=dr["被聘日期"].ToString();
textBox4.Text=dr["电子邮箱"].ToString();
textBox5.Text=dr["姓名"].ToString();
textBox6.Text=dr["学历"].ToString();
textBox7.Text=dr["出生日期"].ToString();
textBox8.Text=dr["邮编"].ToString();
textBox9.Text=dr["性别"].ToString();
textBox10.Text=dr["职务"].ToString();
textBox11.Text=dr["联系方式"].ToString();
textBox12.Text=dr["家庭住址"].ToString();
dr.Close();
}
else
{
MessageBox.Show("No find!");
dr.Close();
}

}

private System.Data.SqlClient.SqlDataReader d()
{
try
{
System.Data.SqlClient.SqlDataReader dr;
System.Data.SqlClient.SqlConnection conn=new System.Data.SqlClient.SqlConnection("server=.;uid=sa;pwd=;database=freeman");
conn.Open();
System.Data.SqlClient.SqlCommand cmd=new System.Data.SqlClient.SqlCommand("select * from 职工档案表",conn);
dr=cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
return dr;
}
catch(Exception e)
{
MessageBox.Show(e.Message);
return null;
}
}

}
}

W1Olupgo.rar (32.73 KB) windows应用程序DataReader的综合应用事例


搜索更多相关主题的帖子: windows 应用程序 DataReader 事例 
2006-05-15 21:20
快速回复:windows应用程序DataReader的综合应用事例
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018377 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved