1.access数据库的连接串:
OleDbConnection con = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("") + "http://www.cnblogs.com/dannyboy/admin/file://App_Data//danny.mdb");
con.Open();
2.OleDbDataReader用法:
OleDbDataReader rd ;
rd= cmd.ExecuteReader();
using System.Data.SqlClient;
3.Dataset的用法
OleDbConnection con = new OleDbConnection("");
con.Open();
OleDbDataAdapter dad = new OleDbDataAdapter("select * from Select_Question", con);
DataSet ds = new DataSet();
dad.Fill(ds, "dannyboy");
// this .Label2 .Text = ds.Tables["dannyboy"].Rows[1][1].ToString();
con.Close();
/////////////////////////////////////////////////
SQL Server
"Data Source=(local);Integrated Security=SSPI;Database=Northwind";
"Data Source = DANNYGIRL;User ID=sa;Password=139020;Database = dannyboy;";
static string strConnection = "Data Source=.;Initial Catalog=qiujiting;Integrated Security=True";
1。执行建立一个表
string con = "Data Source = DANNYGIRL;User ID=sa;Password=139020;Database = dannyboy;";
SqlConnection com = new SqlConnection(con);
com.Open();
string strCom = @"create table personnel (PNumber char(10) ,PName char(10),PPay int,PDep char(10) , primary key (PNumber))";
SqlCommand cmd = new SqlCommand(strCom,com);
cmd.ExecuteNonQuery();
com .Close();
::
2。用dataGrid显示一张表
string con = "Data Source = DANNYGIRL;User ID=sa;Password=139020;Database = dannyboy;";
SqlConnection com = new SqlConnection(con);
com.Open();
SqlDataAdapter ada = new SqlDataAdapter("select * from personnel", com);
DataSet ds = new DataSet();
ada.Fill(ds, "dannyboy");
this.dataGrid1.DataSource = ds.Tables["dannyboy"].DefaultView;
com.Close();
3。datareader的用法。
string con = "Data Source = DANNYGIRL;User ID=sa;Password=139020;Database = dannyboy;";
SqlConnection com = new SqlConnection(con);
com.Open();
string strCom = @"select * from personnel";
SqlCommand cmd = new SqlCommand(strCom,com);
SqlDataReader dr= cmd.ExecuteReader();
MessageBox.Show(dr.FieldCount.ToString());
int i = 0;
while (dr.Read())
{
MessageBox.Show(dr.GetString(i++));
dr.Read();
}
com.Close();
}
/////////////////////
string sSex="F";
if (this.RadioButton1.Checked == true) sSex = "M";
connectionstring cLinkstring = new connectionstring();
SqlConnection com = new SqlConnection(cLinkstring.getconnectionstring());
com.Open();
string strCom = "";
SqlCommand cmd = new SqlCommand(strCom, com);
cmd.ExecuteNonQuery();
com.Close();