System.Data.OleDb.OleDbException: 至少一个参数没有被指定值 5
protectedvoidButton2_Click(objectsender,EventArgse){using(OleDbConnectionconn=newOleD...
protected void Button2_Click(object sender, EventArgs e)
{
using (OleDbConnection conn = new OleDbConnection()) {
conn.ConnectionString = ConfigurationManager.ConnectionStrings["dataConnectionString"].ConnectionString;
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "Insert into [tb_message]([speaker],[content],[dtmDate],[ip])valuse(?,?,?,?)";
cmd.Parameters.Add(new OleDbParameter("speaker", TextBox2.Text));
cmd.Parameters.Add(new OleDbParameter("content", TextBox3.Text));
cmd.Parameters.Add(new OleDbParameter("ip", GetRemoteIP()));
cmd.Parameters.Add(new OleDbParameter("dtmDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
if(cmd.ExecuteNonQuery()>0)
{
TextBox2.Text = "";
TextBox3.Text = "";
ClientScript.RegisterStartupScript(GetType(), "", "alert('留言成功')", true);
}
else
{
ClientScript.RegisterStartupScript(GetType(), "", "alert('留言失败')", true);
}
}
}
} 展开
{
using (OleDbConnection conn = new OleDbConnection()) {
conn.ConnectionString = ConfigurationManager.ConnectionStrings["dataConnectionString"].ConnectionString;
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "Insert into [tb_message]([speaker],[content],[dtmDate],[ip])valuse(?,?,?,?)";
cmd.Parameters.Add(new OleDbParameter("speaker", TextBox2.Text));
cmd.Parameters.Add(new OleDbParameter("content", TextBox3.Text));
cmd.Parameters.Add(new OleDbParameter("ip", GetRemoteIP()));
cmd.Parameters.Add(new OleDbParameter("dtmDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
if(cmd.ExecuteNonQuery()>0)
{
TextBox2.Text = "";
TextBox3.Text = "";
ClientScript.RegisterStartupScript(GetType(), "", "alert('留言成功')", true);
}
else
{
ClientScript.RegisterStartupScript(GetType(), "", "alert('留言失败')", true);
}
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询