c# 从零到精通 读取连接数据库-并执行sql语句,遍历值
using System;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Test09
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection conn;
private void Form1_Load(object sender, EventArgs e)
{
conn = new SqlConnection(“server=MRC-8CF94303A82\MRNET;database=db_15;uid=sa;pwd=111”);
DataSet ds = new DataSet();
DataSet ds1 = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(“select * from tb_test”, conn);
sda.Fill(ds);
SqlDataAdapter sda1 = new SqlDataAdapter(“select * from tb_man”, conn);
SqlCommandBuilder sbl = new SqlCommandBuilder(sda1);
sda1.Fill(ds1);
ds1.Merge(ds,true,MissingSchemaAction.AddWithKey);
dataGridView1.DataSource = ds1.Tables[0];
}
}
}