我是靠谱客的博主 炙热夕阳,这篇文章主要介绍C#将查询到的数据库里面的数据输出到textbox控件,现在分享给大家,希望可以做个参考。

C#连接数据库(类的形式)

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace systemprotect { public partial class bdwxx : Form { public bdwxx() { InitializeComponent(); } private void bdwxx_Load(object sender, EventArgs e) {//C#将查询到的数据库里面的数据输出到textbox控件 this.Text = "本单位信息--系统维护"; DataCon link = new DataCon();//类的内容见博客上面的链接 string sql = "select * from message"; //为指定的command对象执行DataReader SqlDataReader read = link.query(sql);//执行sql语句 while (read.Read()) { Console.WriteLine("{0} {1} ", read["b_id"],read["b_name"]); textBox1.Text = read["b_id"].ToString();//b_id字段名,下同 textBox2.Text = read["b_name"].ToString(); textBox3.Text = read["b_tel"].ToString(); textBox4.Text = read["b_person"].ToString(); textBox5.Text = read["b_adress"].ToString(); } link.close(); Console.ReadLine(); textBox1.ReadOnly = true; textBox2.ReadOnly = true; textBox3.ReadOnly = true; textBox4.ReadOnly = true; textBox5.ReadOnly = true; } private void s(object sender, EventArgs e) { } private void toolStripButton4_Click(object sender, EventArgs e) { Formmainxtwh1 form = new Formmainxtwh1(); form.Show(); this.Hide(); } private void toolStripButton1_Click(object sender, EventArgs e) { textBox1.ReadOnly = false; textBox2.ReadOnly = false; textBox3.ReadOnly = false; textBox4.ReadOnly = false; textBox5.ReadOnly = false; } private void toolStripButton2_Click(object sender, EventArgs e) { string id = textBox1.Text; string name = textBox2.Text; string tel = textBox3.Text; string person = textBox4.Text; string address = textBox5.Text; DataCon link = new DataCon(); string update = "Update message set b_id='" + id + "',b_name='"+name+ "',b_tel='"+tel+ "',b_person='" + person + "',b_adress='" + address + "'"; link.insert(update); link.close(); } private void textBox3_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 0x20) e.KeyChar = (char)0; //禁止空格键 if ((e.KeyChar == 0x2D) && (((TextBox)sender).Text.Length == 0)) return; //处理负数 if (e.KeyChar > 0x20) { try { double.Parse(((TextBox)sender).Text + e.KeyChar.ToString()); } catch { e.KeyChar = (char)0; //处理非法字符 } } } private void toolStripButton3_Click(object sender, EventArgs e) { textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = ""; } private void toolStripButton5_Click(object sender, EventArgs e) { Formmainxtwh1 form = new Formmainxtwh1(); form.Show(); this.Hide(); } } }

最后

以上就是炙热夕阳最近收集整理的关于C#将查询到的数据库里面的数据输出到textbox控件的全部内容,更多相关C#将查询到内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(65)

评论列表共有 0 条评论

立即
投稿
返回
顶部