分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

第四章 ADO.NET

发布时间:2023-09-06 01:26责任编辑:林大明关键词:.NET
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.SqlClient;namespace WindowsFormsApplication1{ ???public partial class Form1 : Form ???{ ???????public Form1() ???????{ ???????????InitializeComponent(); ???????} ???????private void Form1_Load(object sender, EventArgs e) ???????{ ???????????//定义一个需要访问的数据库的信息 ???????????string strCon = "Server=PC-20161029WDCV\\SQL2014;Database=StudentDB;Trusted_Connection=True"; ???????????SqlConnection con = new SqlConnection(strCon); ???????????//打开数据库连接 ???????????con.Open(); ???????????string cmdText = "select * from course"; ???????????SqlDataAdapter da = new SqlDataAdapter(cmdText, con); ???????????//新建一个DataSet,用于接收查询结果 ???????????DataSet ds = new DataSet(); ???????????da.Fill(ds); ???????????//关闭数据库连接 ???????????con.Close(); ???????????//将查询结果的第一个表赋值给dt ???????????DataTable dt = ds.Tables[0]; ???????????txtMsg.Text = "课程号 ???课程名\r\n"; ???????????????????????//foreach (DataRow dr in dt.Rows) ???????????//{ ???????????// ???txtMsg.Text += dr[0].ToString() + " ??" + dr[1].ToString()+"\r\n"; ???????????//} ???????????for (int i = 0; i < dt.Rows.Count; i++) ???????????{ ???????????????txtMsg.Text += dt.Rows[i][0] + " ???" + dt.Rows[i][1] + "\r\n"; ???????????} ???????????lblMsg.Text = "共" + dt.Rows.Count + "条数据"; ???????????//txtMsg.Text += dt.Rows[0][0].ToString() + " ???"+dt.Rows[0]["课程名"].ToString(); ???????} ???}}

第四章 ADO.NET

原文地址:http://www.cnblogs.com/zhang1997/p/7891622.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved