【WinForm】 自学笔记二:连接数据库以及查询结果显示
|
本次使用 SqlConnection 来连接数据库,使用 DataGridView 来显示查询的结果。最终效果如下:
一、连接数据库
1.获取连接数据库所需的字符串,包括服务器名称,数据库名称,用户名以及密码,可在配置文件中配置,或直接在代码里写死
在配置文件 App.config 中配置的代码:
- <configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>
复制代码 View Code2.获取数据库连接对象
- <configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>public static SqlConnection CreateSqlConn()<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>{<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> //从配置文件 App.config 中获取数据库连接字符串<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> var conStr = ConfigurationManager.AppSettings["connectionstring"];<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> SqlConnection conn = new SqlConnection(conStr);<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> return conn;<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>}
复制代码 View Code3.测试数据库的连通性
- <configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>private void button1_Click(object sender, EventArgs e)<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>{<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> try<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> {<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>if (conn.State == ConnectionState.Closed)<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>{<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> conn.Open();<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>}<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>MessageBox.Show("连接成功","数据库连接测试");<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> }<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> catch (Exception ex)<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> {<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>MessageBox.Show("连接失败:"+ ex.Message, "数据库连接测试");<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> }<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>}
复制代码 View Code二、查询数据并在画面上显示
1.在窗口中添加 DataGridView 对象,用于显示数据
右键点击 DataGridView 对象,可以编辑要显示的列,以及表头的名称。
列属性:
DataPropertyName : 数据源中对应字段的名称,根据对应的字段来显示值
HeaderText : 表头显示的文字
DataGridView属性
AllowUserToAddRows :DataGridView默认底部有一行空数据,将改属性修改为False,可以隐藏空白行
AutoSizeColumnsMode:控制列的宽度,将该属性ScrollBars修改为 Fill , 能让列的宽度自适应,充满整个画面
ScrollBars : 控制滚动条的状态,可隐藏滚动条,或只显示水平或垂直的滚动条
2.生成数据查询SQL,并将查询结果绑定到 DataGridView 上,在画面进行显示
- <configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>private void button2_Click(object sender, EventArgs e)<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>{<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> var dataCnt = numericUpDown1.Value;<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> dataCnt = dataCnt > 0 ? dataCnt : 5;<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> string sql = "Select Top " + dataCnt + " UserId,RedId,NickName,[Desc],Location From UserInfo ";<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> var ds = Query(sql);<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> if (ds.Tables?.Count > 0)<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> {<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>var dt = ds.Tables[0];<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>//直接绑定DataTable<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>dataGridView1.DataSource = dt;<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>////绑定对象列表<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>//List userList = new List();<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>//if (dt.Rows?.Count > 0)<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>//{<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>// foreach (DataRow row in dt.Rows)<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>// {<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>//<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>UserInfo user = new UserInfo<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>//<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>{<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>//<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> UserId = row["UserId"] + "",<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>//<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> RedId = row["RedId"] + "",<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>//<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> NickName = row["NickName"] + "",<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>//<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> Desc = row["Desc"] + "",<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>//<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> Location = row["Location"] + "",<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>//<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>};<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>//<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>userList.Add(user);<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>// }<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>//}<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>//dataGridView1.DataSource = userList;<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> }<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>}<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>public DataSet Query(string sqlStr)<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>{<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> DataSet ds = new DataSet();<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> try<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> {<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>if (conn.State == ConnectionState.Closed)<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>{<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> conn.Open();<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>}<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>SqlDataAdapter command = new SqlDataAdapter(sqlStr, conn);<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>command.Fill(ds);<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> }<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> catch (Exception ex)<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> {<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration><configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>throw new Exception(ex.Message);<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> }<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration> return ds;<configuration>
- <appSettings>
- <add key="connectionstring" value="server=192.168.3.201;database=Nine_Xhs;uid=sa;pwd=Nine!2021;"/>
- </appSettings>
- </configuration>}
复制代码 View Code注:DataGridView 对象绑定的数据源,DataTable 以及 对象List 都是可以的,显示的效果是一样的
来源:https://www.cnblogs.com/SuperJason/archive/2023/03/09/17201062.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作! |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|
|
|
发表于 2023-3-9 18:32:56
举报
回复
分享
|
|
|
|