C#连接SqlServer以及插入数据的实例
2014-05-05 20:06
316 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; namespace test2 { class Program { static void Main(string[] args) { string connString = "Data Source=127.0.0.1;" + "Persist Security Info=True;" + "Initial Catalog=TestSql;" + "Integrated Security=false;"+ "User ID=sa;"+ "Password=root123;"; SqlConnection conn = new SqlConnection(connString); try { string insertCommand = "insert into employee (username,password) values('LiHua','123')"; conn.Open(); Console.WriteLine("open database successfully!!!");
SqlCommand command = new SqlCommand(insertCommand,conn); command.ExecuteNonQuery();
} catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.GetType()); Console.WriteLine("connection Exception!!!");
} finally { conn.Close(); Console.WriteLine("close database successfully!!!"); } } } }
相关文章推荐
- C#连接数据库并插入数据(insert)
- 数据结构(C#)--二叉查找树的先序,中序,后序的遍历问题以及最大值,最小值,插入,删除
- C#连接mysql数据库 及向表中插入数据的方法
- C# 连接MongoDB服务器 并插入数据
- C#连接数据库并插入数据
- asp.net(C#) 上传Execl文件 并插入数据到数据库实例
- sqlServer以及Access数据类型与c#数据类型对应表
- JAVA连接SQLServer基础,以及5分钟之内读+写20万条数据(40万条操作),遇到的问题
- C#连接mysql数据库插入数据后获取自增长主键ID值
- C# 在dataGridView中行首或行尾手动添加记录、修改一行记录(1.行尾添加,非数据库连接形式 2.修改某一行的数据 3.插入行首,不覆盖行首)
- 一个C#(.NET)数据访问连接、查询、插入等操作的封装类
- C#连接mysql数据库 及向表中插入数据的方法
- MFC(基于VS2013)连接下位机简单实例(下位机连接以及Socket数据发送接收)
- java封装openTsDb连接以及查询,插入数据
- JAVA连接mysql数据库,动态创建表以及动态插入数据
- c#连接SQLSERVER命名实例的方法
- C#往SQLServer中插入大数据
- asp.net(C#) 上传Execl文件 并插入数据到数据库实例
- c#连接sqlserver数据库、插入数据、从数据库获取时间示例
- C#获得SQLServer服务器名、数据库名、表名、以及字段名【转载】