C# Sql Server连接(增、删、改、查)
2023-09-14 09:03:16 时间
string MyConn = server=127.0.0.1;uid=数据库登录名;pwd=密码;database=数据库的名字;Trusted_Connection=no
SqlConnection MyConnection = new SqlConnection(MyConn);
相信不少人都有删库或被删库的经历。当事情发生后,是跑路,还是自首?相信每个人都没有想过这两个选项,大家首先想到的是如何恢复数据。
string MyConn = "server=127.0.0.1;uid=数据库登录名;pwd=密码;database=数据库的名字;Trusted_Connection=no"; SqlConnection MyConnection = new SqlConnection(MyConn);
string MyInsert = "想要执行的sql语句"; SqlCommand MyCommand = new SqlCommand(MyInsert, MyConnection); MyConnection.Open(); MyCommand.ExecuteNonQuery(); MyConnection.Close();
2、删除
string MyDelete = "想要执行的sql语句"; SqlCommand MyCommand = new SqlCommand(MyDelete, MyConnection); MyConnection.Open(); MyCommand.ExecuteNonQuery(); MyConnection.Close();
3、更新
string MyUpdate = "想要执行的sql语句"; SqlCommand MyCommand = new SqlCommand(MyUpdate, MyConnection); MyConnection.Open(); MyCommand.ExecuteNonQuery(); MyConnection.Close();
4、查询
MyConn.Open(); SqlDataAdapter dap = new SqlDataAdapter("想要执行的sql语句",MyConn); DataSet ds = new DataSet();//实例化DataSet类 dap.Fill(ds, "Table");//添加SQL语句并执行 dataGridView1.DataSource = ds.Tables[0].DefaultView;//显示数据
相信不少人都有删库或被删库的经历。当事情发生后,是跑路,还是自首?相信每个人都没有想过这两个选项,大家首先想到的是如何恢复数据。
相关文章
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C#数据结构与算法揭秘12
- .NET(C#) Dapper Oracle(ODP.NET)或SQL Server 执行多条查询(select)语句的方法代码
- C# socket实践 - 简易版FTP(Server & Client)
- Client使用c#和odp.net连接server oracle
- C# 操作PDF
- C#操作SQL Server中的Image类型数据
- c# 优化代码的一些规则——判断null值得不同写法[六]
- C# 使用Log4Net记录日志(进阶篇)
- C# Sql Server连接(增、删、改、查)
- C# Oracle、Sql Server连接(增、删、改、查)
- C# dev gridcontrol “时间”字符串格式化
- LibXL 4.0.4 for C++ AND c# Crack
- C# Oracle、Sql Server连接(增、删、改、查)
- C# 连接SQL Server数据库的几种方式--server+data source等方式
- C#同步SQL Server数据库中的数据--数据库同步工具[同步新数据]
- C# 中的函数与方法