c# 从零到精通 读取连接数据库-并执行sql语句,遍历值

  • Post author:
  • Post category:其他


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];

}

}

}



版权声明:本文为weixin_43931979原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。