📄 class1.cs
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -