本文介绍了显示数据库中的记录以形成控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 在我的项目中,我正在使用两个表单第一个是登录和第二个emp_detail。 成功登录后第二个表单加载现在我想显示从数据库到表单控件的记录。为此我使用下面的代码,但没有任何东西可以检索。 任何人请 private void Form1_Load(object sender,EventArgs e) { SqlConnection conn = new SqlConnection(@Data Source = .\SQLEXPRESS; AttachDbFilename = C:\Users\manish\Documents\HMM.mdf; Integrated Security = True; Connect Timeout = 30; User Instance = True); conn.Open(); SqlCommand command = new SqlCommand(select * from emp_detail ,conn); SqlDataAdapter adp = new SqlDataAdapter(command); DataTable tbl = new DataTable(); adp.Fill(tbl ); display(); } private void display() { DataTable tbl = new DataTable(); txtempid.Text = tbl.Rows [0] [1] .ToString(); txtname.Text = tbl .Rows [0] [2] .ToStr ing(); txtsurname.Text = tbl.Rows [0] [3] .ToString(); txtfathername.Text = tbl.Rows [0] [4 ] .ToString(); dtdob.Text = tbl.Rows [0] [5] .ToString(); cbgender.Text = tbl.Rows [0] [6] .ToString(); cbcity.Text = tbl.Rows [0] [7] .ToString(); txtcontactno.Text = tbl.Rows [ 0] [8] .ToString(); dtdoj.Text = tbl.Rows [0] [9] .ToString(); txtdept.Text = tbl。行[0] [10] .ToString(); txtdesig.Text = tbl.Rows [0] [11] .ToString(); txtqualification.Text = tbl.Rows [0] [12] .ToString(); rtaddress.Text = tbl.Rows [0] [13] .ToString(); rtremarks。 Text = tbl.Rows [0] [14] .ToString(); } 解决方案 In my project i am using two form 1st one is login and 2nd emp_detail.after successful login 2nd form loaded now i want to show record from database to form controls . For this i using below code but nothing is retrieve.anyone please private void Form1_Load(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\manish\Documents\HRM.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"); conn.Open(); SqlCommand command = new SqlCommand("select * from emp_detail", conn); SqlDataAdapter adp = new SqlDataAdapter(command); DataTable tbl= new DataTable(); adp.Fill(tbl); display(); } private void display() { DataTable tbl= new DataTable(); txtempid.Text = tbl.Rows[0][1].ToString(); txtname.Text = tbl.Rows[0][2].ToString(); txtsurname.Text = tbl.Rows[0][3].ToString(); txtfathername.Text = tbl.Rows[0][4].ToString(); dtdob.Text = tbl.Rows[0][5].ToString(); cbgender.Text = tbl.Rows[0][6].ToString(); cbcity.Text = tbl.Rows[0][7].ToString(); txtcontactno.Text = tbl.Rows[0][8].ToString(); dtdoj.Text = tbl.Rows[0][9].ToString(); txtdept.Text = tbl.Rows[0][10].ToString(); txtdesig.Text = tbl.Rows[0][11].ToString(); txtqualification.Text = tbl.Rows[0][12].ToString(); rtaddress.Text = tbl.Rows[0][13].ToString(); rtremarks.Text = tbl.Rows[0][14].ToString(); } 解决方案 这篇关于显示数据库中的记录以形成控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-31 11:46