当前位置:网站首页>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
边栏推荐
- CUMCM 2021-b: preparation of C4 olefins by ethanol coupling (2)
- PlatoFarm推出正式版游戏经济模型的特点分析
- MySQL failed to insert the datetime type field without single quotation marks
- Visual common drawing (III) area map
- MBA-day6 逻辑学-假言推理练习题
- How to quickly query 10 million pieces of data in MySQL
- Visualization Road (11) detailed explanation of Matplotlib color
- Oracle connectivity test gadget
- 26. Delete duplicates in ordered array
- 学习 Go 语言 0x03:理解变量之间的依赖以及初始化顺序
猜你喜欢

初探 Lambda Powertools TypeScript

vm设置静态虚拟机

Solutions to common problems in visualization (IX) background color

《Neo4j权威指南》简介,求伯君、周鸿袆、胡晓峰、周涛等大咖隆重推荐

Solutions to common problems in visualization (VIII) solutions to problems in shared drawing area

Cygwin 中的 rename 用法

升级cpolar内网穿透能获得的功能

年度最尴尬的社死瞬间,是Siri给的

PDMS软光刻加工过程

An interesting interview question
随机推荐
Mysql8.0安装指南
web三大组件(Servlet,Filter,Listener)
卷积层和池化层总结
学习 Go 语言 0x02:对切片 Slice 的理解
Usage Summary of datetime and timestamp in MySQL
详解MySQL中timestamp和datetime时区问题导致做DTS遇到的坑
期货开户哪个公司好?安全靠谱的期货公司谁能推荐几家?
Microsoft Access database using PHP PDO ODBC sample
MBA-day6 逻辑学-假言推理练习题
小程序 支付
Mysql中有关Datetime和Timestamp的使用总结
mysql插入datetime类型字段不加单引号插入不成功
Mba-day5 Mathematics - application problems - engineering problems
初探 Lambda Powertools TypeScript
MySQL面试题讲解之如何设置Hash索引
如何使用JDBC CallableStatement.wasNull()方法调用来查看最后一个OUT参数的值是否为 SQL NULL
《Neo4j权威指南》简介,求伯君、周鸿袆、胡晓峰、周涛等大咖隆重推荐
Mysql系列SQL查询语句书写顺序及执行顺序详解
Learn go language 0x07: stringer exercise code in go language journey
remote: Support for password authentication was removed on August 13, 2021.