using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnectionStringBuilder db = new SqlConnectionStringBuilder();
db.DataSource = "127.0.0.1";
db.UserID = "sa";
db.Password = "123456789";
db.InitialCatalog = "bookshop";
SqlConnection conn = new SqlConnection(db.ToString());
if (conn.State == System.Data.ConnectionState.Closed)
conn.Open();
string strSQL = "select * from [bookshop].[dbo].[user]";
SqlDataAdapter da = new SqlDataAdapter(strSQL, conn);
DataSet ds = new DataSet();
da.Fill(ds, "user");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "user";
}
}
}
并用datagridview和dataset进行显示