Sqlserver数据库连接方式有多种,这里只介绍最常用的通过SqlConnection和Sqlserver数据库用户名和密码验证来进行操作数据库。
数据库连接字符串:
string connString = "data source=119.180.261.117,1433;initial catalog=anxiuyun;user id=sa;pwd=sa";
这里data source 是指数据库地址和端口号,需要注意的是地址和端口号之间是用","进行分隔的;initial catalog 是数据库名字 ;user id和pwd分别指用户名和密码。
数据库建立连接:
 SqlConnection sqlConnection = new SqlConnection(this.connString);
 sqlConnection.Open();
数据库查询:
SqlDataAdapter sqlDa = new SqlDataAdapter("select * from tb_alarm", sqlConnection);
DataTable dt = new DataTable();
sqlDa.Fill(dt);
数据库插入更新操作:
SqlCommand sqlCmd = new SqlCommand("insert into tb_scene_tb (id,scene_id) values('1','123')", sqlConnection);
sqlCmd.ExecuteNonQuery();

C#通过SqlConnection连接查询更新等操作Sqlserver数据库的更多相关文章

  1. Java连接并操作SQLServer数据库

    本人只需在项目中引入sqljdbc4.jar 包即可 ----------------------------------------- 在JAVA中如何连接SQL Server数据库 - hangh ...

  2. ORACLE 通过连接查询更新 update select

    注意:  关键的地方是where 语句的加入. 在11G中, 如果不加11G , 或造成除匹配的行数更新为相应的值之后, 其余的会变成负数. 所以,执行前需要测试, 普通办法就是:  先查看需要更新的 ...

  3. C#中简单操作SQLserver数据库(ADO.NET的简单应用)

    本篇文章以 ADO.NET 访问SQL SERVER 数据库为例, 其中需用System.Data.SqlClient; 数据库连接字符串写法为:server=数据源(服务器名称);uid=用户名;p ...

  4. 在SqlServer查询分析器里 访问远程数据库 进行数据查询更新等操作(openrowset)

    启用Ad Hoc Distributed Queries: exec sp_configure 'show advanced options',1 reconfigure exec sp_config ...

  5. MongoDB中的映射,限制记录和记录拼排序 文档的插入查询更新删除操作

    映射 在 MongoDB 中,映射(Projection)指的是只选择文档中的必要数据,而非全部数据.如果文档有 5 个字段,而你只需要显示 3 个,则只需选择 3 个字段即可. find() 方法 ...

  6. shell脚本连接、读写、操作mysql数据库实例

    本文介绍了如何在shell中读写mysql数据库.主要介绍了如何在shell 中连接mysql数据库,如何在shell中创建数据库,创建表,插入csv文件,读取mysql数据库,导出mysql数据库为 ...

  7. python开发笔记-pymsslq连接操作SqlServer数据库

    1. 普通连接测试 官方文档样例:http://pymssql.org/en/latest/pymssql_examples.html pymssql模块使用指南:https://blog.csdn. ...

  8. 操作sqlserver数据库常用的三个方法

    1. ADO.NET -> 连接字符串,常用的两种方式: server=计算机名或ip\实例名;database=数据库名;uid=sa;pwd=密码; server=计算机名或ip\实例名;d ...

  9. php+sqlserver之如何操作sqlserver数据库

    https://blog.csdn.net/xia13100004562/article/details/58598872 2016年12月19日 17:15:39 阅读数:6790 前面已经基本配置 ...

随机推荐

  1. codeforces 371B - Fox Dividing Cheese

    #include<stdio.h> int count; int gcd(int a,int b) { if(b==0) return a;     return gcd(b,a%b); ...

  2. CF576D. Flights for Regular Customers

    n<=150个点,m<=150条路,每条路Ai,Bi,Di表示Ai到Bi有一条有向边,使用他前至少要走Di条路,问1到n最少走几条路. 又是n^4过150的题.... 不同于传统的最短路, ...

  3. poj 3074

    题意:解数独 分析: 完整的数独有四个充要条件: 1.每个格子都有填数字 2.每列都有1~9中的每个数字 3.每行都有1~9中的每个数字 4.每个9宫格都有1~9中的每个数字 可以转化成精确覆盖问题. ...

  4. Ubuntu 16.04设置文件夹试图永久以列表显示

    图片来自:http://forum.ubuntu.org.cn/viewtopic.php?p=2043385

  5. ZooKeeper实现配置中心的实例(原生API实现)(转)

    说明:要实现配置中心的例子,可以选择的SDK有很多,原生自带的SDK也是不错的选择.比如使用I0Itec,Spring Boot集成等. 大型应用通常会按业务拆分成一个个业务子系统,这些大大小小的子应 ...

  6. LVS中文站点

    http://blog.csdn.net/turkeyzhou/article/details/16980161 http://zh.linuxvirtualserver.org/

  7. Spring的AOP特性

    一.AOP简介 AOP是Aspect-Oriented Programming的缩写,即面向切面编程.利用oop思想,可以很好的处理业务流程,但是不能把系统中某些特定的重复性行为封装到模块中.例如,在 ...

  8. LeetCode 350. Intersection of Two Arrays II (两个数组的相交之二)

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  9. LeetCode 237. Delete Node in a Linked List (在链表中删除一个点)

    Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...

  10. Codesys——限定符的使用方法[来自Codesys的Help]

    Qualifier for actions in SFC In order to configure in which way the actions should be associated to ...