执行insert into语句的问题

Nils Nils 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
OleDbConnection con = new OleDbConnection();

private void OpenDatabase()
{
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("book.mdb");
con.Open();
}

private void Buttonok_Click(object sender, System.EventArgs e)
{
OleDbConnection myConnection = con;
OleDbCommand cmd;
string sql = "insert into [f_bbs] (f_name,head,f_content,f_oicq,f_email,f_homepage) values ('{0}','{1}','{2}','{3}','{4}','{5}')";
sql = string.Format(sql,this.TextBoxname.Text,this.Rblist.SelectedItem.Value,this.nr.Text,this.TextBoxoicq.Text,this.TextBoxmail.Text,this.TextBoxurl.Text);
cmd = new OleDbCommand(sql,myConnection);
try
{
cmd.ExecuteScalar();
}
catch
{
con.Close();
}


不会报错,就是插不进去数据。我将sql用response打出来,然后到数据库里执行就可以。谁看看哪的问题
...全文
评论 8
收藏 已收藏
分享
返回顶部
Nils
.NET社区 62,275 成员 668,968 内容