[C#] VS2012连接SQL Server2012数据库的连接方式
2014-07-14 10:07
246 查看
</pre><pre name="code" class="csharp">SqlConnection conn = new SqlConnection("server=服务器名;database=数据库名;user=用户名;password=密码;"); try { 查询 conn.Open(); string sql = "select * from table"; SqlCommand sc = new SqlCommand(sql, conn); SqlDataReader sr = sc.ExecuteReader(); sc.Read(); int id = sr1.GetInt32(0); 插入 string sql = "insert into values (@Id,@Class)"; SqlCommand sc = new SqlCommand(sql, conn); SqlParameter para1 = new SqlParameter("@Id", SqlDbType.Int, 4); para1.Value = id; sc.Parameters.Add(para1); SqlParameter para2 = new SqlParameter("@Class", SqlDbType.NChar, 20); para2.Value = classs; sc.Parameters.Add(para2); sc.ExecuteNonQuery(); conn.Close(); }
相关文章推荐
- C#不同数据库连接方式对应的Sql语句的构造
- c#中数据库字符串的连接几种方式
- c#中数据库字符串的连接几种方式
- C#中的数据库的连接方式分类说明(转载)
- C# 使用oledb 方式连接本地或者远程oracel 数据库的方式
- C#连接 SQL server数据库 数据库是Windows验证方式登录的
- 【C#】在VS2012中连接MSSQL数据库
- .NET的C#中数据库连接方式
- C# sql Server 项目数据库连接方式探讨
- C#与数据库的连接的三种方式
- C# 连接 Oracle 数据库(三种方式:OracleClient、ODBC、OLEDB)
- C#连接数据库_使用读取配置文件的方式
- C#实现连接SQL Server2012数据库并执行SQL语句的方法
- vs2012 c# GridView控件连接sql 数据库
- c# cs方式操作数据库 非使用sql连接字符串直接连接数据库
- C#中数据库连接的几种方式
- C#(ASP.NET)中连接数据库的字符串(连接Access和sqlserver数据库以及用windows和身份验证两种方式)
- C#中通过OLE方式连接informix数据库与查询数据方式
- 【C#】在VS2012中连接MSSQL数据库
- 四种数据库连接方式