using System;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Test07
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection conn;
private void button1_Click(object sender, EventArgs e)
{
conn = new SqlConnection("server=192.168.1.145;database=lydb;uid=sa;pwd=123@abc");
SqlCommand cmd = new SqlCommand("select * from student", conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds, "cs");
dataGridView1.DataSource = ds.Tables[0];
}
}
}
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Test07
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection conn;
private void button1_Click(object sender, EventArgs e)
{
conn = new SqlConnection("server=192.168.1.145;database=lydb;uid=sa;pwd=123@abc");
SqlCommand cmd = new SqlCommand("select * from student", conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds, "cs");
dataGridView1.DataSource = ds.Tables[0];
}
}
}
本文介绍了一个使用 C# 进行 SQL 数据查询的例子,通过连接数据库并执行查询操作来展示如何从 student 表中获取数据,并将结果显示在 Windows Forms 应用的数据网格视图中。
801

被折叠的 条评论
为什么被折叠?



