C# sql server
来源:互联网 发布:settime js 编辑:程序博客网 时间:2024/06/05 17:12
1. 在 App.config 设置数据库信息
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="TestdataClientConnStr" value="Data Source=数据库名称;Initial Catalog=Table名称;Integrated Security=SSPI;Application Name=Parser;" /> //用window验证登录
<add key="TestdataEditorConnStr" value="Data Source=数据库名称;Initial Catalog=Table名称;Integrated Security=SSPI;Application Name=Parser;" /> //用window验证登录
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
2.在.cs 中链接数据库
using (SqlConnection conn = GetClientConnection()) /连接数据库
using(SqlCommand cmd = new SqlCommand("cfg.getcfgPoints",conn)) / 指定执行的procedure
{
conn.open() /开始连接
cmd.CommandType = CommandType.storedProcedure ; / system.data.CommandType
SqlDataReader dr = cmd.ExecuteReader() // system.data.SqlClient.SqlDataReader
while(dr.read())
{
CfgTablePoints configTablePoint = new CfgTablePoints();
configTablePoint.TableName = dr["table_name"].ToString();
configTablePoint.DataPointName = dr["datapoint_name"].ToString();
configTablePoint.Xpath = dr["xpath"].ToString();
configTablePoint.ChildTableName = (dr["child_table_name"] == DBNull.Value) ? null : dr["child_table_name"].ToString();
configTablePoint.IsKey = (dr["is_key"] == DBNull.Value) ? false : Convert.ToBoolean(dr["is_key"]);
if (dr["data_type"] == DBNull.Value)
{
configTablePoint.DataType = DataType.Undefined;
}
else
{
configTablePoint.DataType = (DataType)Enum.Parse(typeof(DataType), dr["data_type"].ToString(), true);
}
......
}
return talbeNameConfigListDictionary;
}
- visual c# && SQL Server
- C# 连接 SQL Server
- c#连接sql server
- C#连接SQL Server
- C#连接sql server
- C#操作sql server
- c# 链接sql server
- C# 操作 sql server
- C#连接SQL server
- C# sql server
- c#调用 SQL SERVER
- C#连接SQL Server
- c# sql server数据库连接类
- c#启动Sql Server服务
- C#连接SQL SERVER数据库
- C# 连接SQL Server数据库
- C# 连接SQL Server数据库
- sql server call c# assembly
- top.location.href和localtion.href有什么不同
- 等高线下载教程
- java规范
- 部署 Job (第四部分)
- 《构建之法》 读后感 —— there is no silver bullet
- C# sql server
- RSA非对称加密方案
- maven的pom.xml的配置文件说明
- Android Studio 集成git上传项目至GitHub
- 普及练习场之排序Ex
- java 下载文件
- 【常见面试算法题】之二分搜索
- 实现控件拖动
- LeetCode 34 Search for a Range