温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:我的VS2008通讯录项目源码
当前文件:
MyPhoneBook/Mypb/add.aspx.cs,打开代码结构图
MyPhoneBook/Mypb/add.aspx.cs,打开代码结构图1using System.Data.OleDb; 2
using System; 3
using System.Collections; 4
using System.Configuration; 5
using System.Data; 6
using System.Linq; 7
using System.Web; 8
using System.Web.Security; 9
using System.Web.UI; 10
using System.Web.UI.HtmlControls; 11
using System.Web.UI.WebControls; 12
using System.Web.UI.WebControls.WebParts; 13
using System.Xml.Linq; 14
15
namespace Mypb 16
{ 17
public partial class add : System.Web.UI.Page 18
{ 19
protected void Page_Load(object sender, EventArgs e) 20
{ 21
this.Title = "添加新纪录"; 22
TextBox1.Focus(); 23
} 24
25
protected void Button2_Click(object sender, EventArgs e) 26
{ 27
OleDbConnection conn = new OleDbConnection(); 28
conn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;" + "Data Source = " + Server.MapPath("App_Data/Myphonebook.mdb"); 29
//string strVal = TextBox1.Text + "," + TextBox2.Text.ToString() + "," + TextBox3.Text.ToString(); 30
string strVal = "'" + TextBox1.Text +"'," + "'"+ TextBox2.Text + "'," +"'"+ TextBox3.Text+"'"; 31
string strIns = "insert into 通信录(姓名,电话,Email) values(" + strVal + ")"; 32
OleDbCommand insCom = new OleDbCommand(strIns, conn); 33
OleDbDataAdapter da = new OleDbDataAdapter(); 34
conn.Open(); 35
da.InsertCommand = insCom; 36
da.InsertCommand.ExecuteNonQuery(); 37
conn.Close(); 38
Response.Write("<script language=javascript>alert('新纪录添加成功,请单击“返回”回到主页面!');</script>"); 39
} 40
41
protected void Button1_Click(object sender, EventArgs e) 42
{ 43
Response.Redirect("default.aspx"); 44
} 45
} 46
} 47





}
}