当前位置:网站首页>C#的学习笔记【八】SQL【一】
C#的学习笔记【八】SQL【一】
2022-04-23 11:15:00 【BoomBiuBiu】
此处需要下载SQL,我下载的是2019版本,安装链接放在下面:
在安装的过程中会遇到一些问题,可以看下面这个链接,基本上能解决问题:
【实例 1】创建与本机 SQL Server 数据库的连接,并使用异常处理。
根据题目要求,连接 SQL Server 数据库时使用的用户名为 sa、密码为 123456789,【此处的账号密码是可以变成你自己设置的】连接的数据库为Test。【注意看自己数据库上的名称】,此处登录遇到问题,可以看以下的链接:
需要在SQL上新建一个数据库名称为Test的数据库,才能显示链接成功
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 SQL
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//编写数据库连接串
string connStr = "Data source=.;Initial Catalog=Test;User ID=sa;Password=123456789";
//创建SqlConnection的实例
SqlConnection conn = null;
try
{
conn = new SqlConnection(connStr);
//打开数据库连接
conn.Open();
MessageBox.Show("数据库连接成功!");
}
catch (Exception ex)
{
MessageBox.Show("数据库连接失败!" + ex.Message);
}
finally
{
if (conn != null)
{
//关闭数据库连接
conn.Close();
}
}
}
}
}
版权声明
本文为[BoomBiuBiu]所创,转载请带上原文链接,感谢
https://blog.csdn.net/BoomBiuBiu/article/details/124355008
边栏推荐
- Mysql中一千万条数据怎么快速查询
- Detailed explanation of MySQL creation stored procedure and function
- Mysql8. 0 installation guide
- Mba-day5 Mathematics - application problems - engineering problems
- Upgrade the functions available for cpolar intranet penetration
- 学习 Go 语言 0x08:《Go 语言之旅》中 练习使用 error
- 《Neo4j权威指南》简介,求伯君、周鸿袆、胡晓峰、周涛等大咖隆重推荐
- 第六站神京门户-------手机号码的转换
- 语雀文档编辑器将开源:始于但不止于Markdown
- SVN的使用:
猜你喜欢
比深度学习更值得信赖的模型ART
Structure of C language (Advanced)
Detailed explanation of typora Grammar (I)
CUMCM 2021-B:乙醇偶合制備C4烯烴(2)
Solutions to common problems in visualization (VIII) solutions to problems in shared drawing area
MIT:用无监督为世界上每个像素都打上标签!人类:再也不用为1小时视频花800个小时了
分享两个实用的shell脚本
Redis optimization series (II) redis master-slave principle and master-slave common configuration
得物技术网络优化-CDN资源请求优化实践
R-Drop:更强大的Dropout正则方法
随机推荐
MySQL failed to insert the datetime type field without single quotation marks
MySQL数据库10秒内插入百万条数据的实现
Software testers, how to mention bugs?
Solutions to common problems in visualization (VIII) solutions to problems in shared drawing area
Detailed explanation of integer data type tinyint in MySQL
web三大组件(Servlet,Filter,Listener)
Usage Summary of datetime and timestamp in MySQL
学习 Go 语言 0x05:《Go 语言之旅》中映射(map)的练习题代码
年度最尴尬的社死瞬间,是Siri给的
Visual common drawing (I) stacking diagram
Promise详解
Canvas详解
@Valid, @ validated learning notes
Visual common drawing (V) scatter diagram
MySQL partition table can be classified by month
Detailed explanation of how to smoothly go online after MySQL table splitting
About the three commonly used auxiliary classes of JUC
数据库管理软件SQLPro for SQLite for Mac 2022.30
Mysql database transaction example tutorial
ffmpeg命令行常用参数