class1.cs
来自「C#2005 实例源代码」· CS 代码 · 共 47 行
CS
47 行
using System;
using System.Data;
using System.Data.SqlClient;
namespace SqlDataAdapter_Create
{
/// <summary>
/// 使用SqlCommand实现一个SQL语句
/// </summary>
class T
{
/// <summary>
/// 使用SqlCommand实现一个SQL语句
/// </summary>
private void CreateSqlCommand()
{
//连接数据库
SqlConnection myCon = new SqlConnection("Persist Security Info=False;User id=sa;pwd=sa;database=northwind;server=(local)");
myCon.Open();
//使用SqlCommand
SqlCommand selectCMD = new SqlCommand("SELECT top 10 CustomerID, CompanyName FROM Customers",myCon);
//获取数据适配器
SqlDataAdapter custDA = new SqlDataAdapter();
custDA.SelectCommand = selectCMD;
//提交查询,获取结果数据集
DataSet custDS=new DataSet();
custDA.Fill(custDS);
//断开连接
myCon.Close();
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
T t=new T();
t.CreateSqlCommand();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?