第一次使用C#连接数据库。记录一下~
使用winform中的dataGridview来显示从数据库中获取到的数据。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace sql_test
{
public partial class Form1 : Form
{
public DataTable select()
{
SqlCommand com = new SqlCommand();
com.Connection = new BaseDao().getconnection();
com.CommandType = CommandType.Text;
com.CommandText = "select * from admin;";
DataTable ds = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(com);
sda.Fill(ds);
return ds;
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArg