欢迎光临

木子屋

标题: 3个常用的VS2008数据库连接代码段

作者: dnawo

日期: 2012-01-31 04:21 PM

分类: Win编程

内容: conn.snippet：
复制内容到剪贴板 程序代码<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>创建SqlConnection</Title>
<Shortcut>conn</Shortcut>
<Description>-</Description>
<Author>dnawo</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>dbname</ID>
<ToolTip>数据库名称</ToolTip>
<Default>hello</Default>
</Literal>
<Literal>
<ID>userid</ID>
<ToolTip>用户名</ToolTip>
<Default>sa</Default>
</Literal>
<Literal>
<ID>password</ID>
<ToolTip>密码</ToolTip>
<Default>sa</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[
using (SqlConnection conn = new SqlConnection("server=(local);database=$;user id=$;password=$;min pool size=20;max pool size=100;Connection Lifetime=30;Enlist=true;"))
{
$
}
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
cmd.snippet：
复制内容到剪贴板 程序代码<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>创建SqlCommand</Title>
<Shortcut>cmd</Shortcut>
<Description>-</Description>
<Author>dnawo</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>sql</ID>
<ToolTip>查询语句</ToolTip>
<Default>select</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[
conn.Open();
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = conn;
cmd.CommandText = "$";

$
}
conn.Close();
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
adapter.snippet：
复制内容到剪贴板 程序代码<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>创建SqlDataAdapter</Title>
<Shortcut>adapter</Shortcut>
<Description>-</Description>
<Author>dnawo</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>sql</ID>
<ToolTip>查询语句</ToolTip>
<Default>select</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[
using (SqlDataAdapter adapter = new SqlDataAdapter("$", conn))
{
DataTable table = new DataTable();
DataRow row;
adapter.Fill(table);
for (int i = 1; i < table.Rows.Count; i++)
{
row = table.Rows[i];
$
}
}
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

+ 查看当前日志评论 (0)

登录

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 0.957 ms

返回

标题: 3个常用的VS2008数据库连接代码段

你没有权限发表评论

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 0.957 ms

返回

暂无评论

返回

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 0.988 ms

返回