c#datagridview怎么显示SQL SERVER数据库中的表.
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataSet aa = new DataSet();
SqlDataAdapter bb;
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection cc = new SqlConnection("Data Source=XP-201201161804\\SQLEXPRESS;Initial Catalog=WB;Integrated Security=True");
//cc.Open();
string sql = "select * from userInfo";
bb = new SqlDataAdapter(sql, cc);
bb.Fill(aa);
dataGridView1.DataSource = aa.Tables["userInfo&quo 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataSet aa = new DataSet();
SqlDataAdapter bb;
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection cc = new SqlConnection("Data Source=XP-201201161804\\SQLEXPRESS;Initial Catalog=WB;Integrated Security=True");
//cc.Open();
string sql = "select * from userInfo";
bb = new SqlDataAdapter(sql, cc);
bb.Fill(aa);
dataGridView1.DataSource = aa.Tables["userInfo&quo 展开
1个回答
展开全部
using System.Data.SqlClient;
using System.Data;
SqlConnection Conn = new SqlConnection(@"server=DQ\SQLEXPRESS;database=persons;uid=sa;pwd='12345'");
string sql = "select * from [grade]";
SqlDataAdapter da = new SqlDataAdapter(sql, Conn);
DataSet ds = new DataSet();
da.Fill(ds, "grde");
dataGridView1.DataSource = ds;
dataGridView1.DataSource = ds.Tables["grde"];
Conn.Close();
ds.Dispose();
da.Dispose();
using System.Data;
SqlConnection Conn = new SqlConnection(@"server=DQ\SQLEXPRESS;database=persons;uid=sa;pwd='12345'");
string sql = "select * from [grade]";
SqlDataAdapter da = new SqlDataAdapter(sql, Conn);
DataSet ds = new DataSet();
da.Fill(ds, "grde");
dataGridView1.DataSource = ds;
dataGridView1.DataSource = ds.Tables["grde"];
Conn.Close();
ds.Dispose();
da.Dispose();
追问
我晕加了个表名在后面就好了 ,谢谢啦。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询