兰保明

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
 1    
2 protected void ViewData_Click(object sender, EventArgs e)
3 {
4 string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
5 strConnection += Server.MapPath("mydata.mdb");
6 OleDbConnection objConnection = new OleDbConnection(strConnection);
7
8 OleDbCommand objCommand = new OleDbCommand("select*from 通信录", objConnection);
9 objConnection.Open();
10 OleDbDataReader objDataReader = objCommand.ExecuteReader();
11 String str = " ";
12 ArrayList values = new ArrayList();
13 while (objDataReader.Read())
14 {
15 TBId.Text=Convert.ToString(objDataReader["ID"]);
16 TBName.Text = Convert.ToString(objDataReader["name"]);
17 TBClass.Text=Convert.ToString(objDataReader["classm"]);
18 TBTelephone.Text = Convert.ToString(objDataReader["telephone"]);
19 TBEmail.Text = Convert.ToString(objDataReader["Email"]);
20 TBAdress.Text = Convert.ToString(objDataReader["Adress"]);
21
22 String str2=Convert.ToString(objDataReader["ID"]) + str + Convert.ToString(objDataReader["name"]) + str + Convert.ToString(objDataReader["classm"]) + str + Convert.ToString(objDataReader["telephone"]) + str + Convert.ToString(objDataReader["Email"])+ str + Convert.ToString(objDataReader["Adress"]);
23 values.Add(str2);
24 //Response.Write("<br>");//输出回车换行
25 }
26 ListBox.DataSource = values;
27 ListBox.DataBind();
28 values.Clear();
29 objDataReader.Close();
30 objConnection.Close();
31 }
32 protected void FindData_Click(object sender, EventArgs e)
33 {
34 string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
35 strConnection += Server.MapPath("mydata.mdb");
36 OleDbConnection objConnection = new OleDbConnection(strConnection);
37 objConnection.Open();
38 string m_select;
39 string m_id = Convert.ToString(TBId.Text);
40 m_select = "select*from 通信录 where ID ='" + m_id + "'";
41 OleDbCommand objCommand = new OleDbCommand(m_select, objConnection);
42 OleDbDataReader objDataReader = objCommand.ExecuteReader();
43 while (objDataReader.Read())
44 {
45 TBId.Text = Convert.ToString(objDataReader["ID"]);
46 TBName.Text = Convert.ToString(objDataReader["name"]);
47 TBClass.Text = Convert.ToString(objDataReader["classm"]);
48 TBTelephone.Text = Convert.ToString(objDataReader["telephone"]);
49 TBEmail.Text = Convert.ToString(objDataReader["Email"]);
50 TBAdress.Text = Convert.ToString(objDataReader["Adress"]);
51 }
52 objDataReader.Close();
53 objConnection.Close();
54
55 }
56 protected void AddData_Click(object sender, EventArgs e)
57 {
58 string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
59 strConnection += Server.MapPath("mydata.mdb");
60 OleDbConnection objConnection = new OleDbConnection(strConnection);
61 string StrInsert;
62 string m_id = Convert.ToString(TBId.Text);
63 string m_name = Convert.ToString(TBName.Text);
64 string m_class = Convert.ToString(TBClass.Text);
65 string m_telephone = Convert.ToString(TBTelephone.Text);
66 string m_email = Convert.ToString(TBEmail.Text);
67 string m_adress = Convert.ToString(TBAdress.Text);
68 StrInsert = "insert into 通信录(ID,name,classm,telephone,Email,Adress)values('" + m_id + "','" + m_name + "','" + m_class + "','" + m_telephone + "','" + m_email + "','" + m_adress + "')";
69 OleDbCommand objCommand = new OleDbCommand(StrInsert, objConnection);
70 objConnection.Open();
71 int a = objCommand.ExecuteNonQuery();
72 objConnection.Close();
73 }
74 protected void UpdateData_Click(object sender, EventArgs e)
75 {
76 string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
77 strConnection += Server.MapPath("mydata.mdb");
78 OleDbConnection objConnection = new OleDbConnection(strConnection);
79 objConnection.Open();
80 string m_update;
81 string m_id = Convert.ToString(TBId.Text);
82 string m_name = Convert.ToString(TBName.Text);
83 m_update = "update 通信录 set name='" + m_name + "'where ID='" + m_id + "'";
84 OleDbCommand objCommand = new OleDbCommand(m_update, objConnection);
85
86 OleDbDataReader objDataReader = objCommand.ExecuteReader();
87 objDataReader.Close();
88 objConnection.Close();
89 }
90

posted on 2011-08-10 15:39  兰保明  阅读(211)  评论(0编辑  收藏  举报