protected void Button2_Click(object sender, EventArgs e)

{OleDbConnectionconn=newOleDbConnection();conn.ConnectionString="Provider=Microsoft.J... {
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;" + "Data Source = " + Server.MapPath("App_Data/Myphonebook.mdb");

// string strVal = "'" + TextBox1.Text + "','" +ddlSex.SelectedValue+ "','" + TextBox2.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "," + TextBox6.Text + "','" + TextBox3.Text + "'";
string strIns = "insert into 通信录(姓名,性别,年级,专业,籍贯,电话,Email) values('" + TextBox1.Text + "','" +ddlSex.SelectedValue+ "','" + TextBox2.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "," + TextBox6.Text + "','" + TextBox3.Text + "')";

conn.Open();

OleDbCommand insCom = new OleDbCommand(strIns, conn);
// OleDbDataAdapter da = new OleDbDataAdapter();
insCom.ExecuteNonQuery();

//da.InsertCommand = insCom;
// da.InsertCommand.ExecuteNonQuery();
conn.Close();
Response.Write(1111111);
// Response.Write("<script language=javascript>alert('新纪录添加成功,请单击“返回”回到主页面!');</script>");
}
这行代码有错误么,怎么数据存不到Access数据库里面?
展开
 我来答
平梦醉神风1I
2011-07-25 · TA获得超过1510个赞
知道小有建树答主
回答量:691
采纳率:0%
帮助的人:1037万
展开全部
应该是数据库路径有错误
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;" + "Data Source = " + Server.MapPath("~/App_Data/Myphonebook.mdb");
string strIns = string.Format("insert into 通信录(姓名,性别,年级,专业,籍贯,电话,Email) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", TextBox1.Text, ddlSex.SelectedValue, TextBox2.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text, TextBox3.Text);
OleDbCommand insCom = new OleDbCommand(strIns, conn);
int result = -1;
conn.Open();
result = insCom.ExecuteNonQuery();
conn.Close();
Response.Write(result);
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式