C#连接到数据库
小弟刚刚开始学用C#来实现对数据库的连接访问。老师给了一段代码
namespace AdoTest
{
public partial class Form1 : Form
{
private SqlDataReader dr;
private DataSet ds;
private BindingSource bs;
public Form1()
{
InitializeComponent();
ds = new DataSet();
bs = new BindingSource();
}
private void ChuShiHua()
{
string ssql= "select * from student";
//SqlCommand cmd=new SqlCommand(ssql,cn);
SqlDataAdapter ad = new SqlDataAdapter(ssql,ConfigurationManager.ConnectionStrings["connString"].ConnectionString);
ds.Clear();
ad.Fill(ds, "student");
//textBox2.Text = ds.Tables["student"].Rows[0]["sname"].ToString();
bs.DataSource = ds;
bs.DataMember ="student";
bindingNavigator1.BindingSource = bs;
dataGridView1.DataSource = bs;
//dataGridView1.DataSource = ds.Tables["student"];
//textBox1.DataBindings.Add("Text", ds.Tables["student"], "sno");
//bindingSource1.DataSource = ds.Tables["student"];
//bindingNavigator1.BindingSource=new BindingSource(ds,"student");
//bindingNavigator1.BindingSource.DataMember="student";
}
private SqlDataReader dr;
private DataSet ds;
private BindingSource bs;
不明白这三行的作用,为什么要放在开头以及用PRIVATE,求大神解答,谢谢!
免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。