日期:2014-05-18 浏览次数:20445 次
protected void Button1_Click(object sender, EventArgs e) { hostname = Request.QueryString["id"].ToString();//全局变量,此处无错。 string str = System.Web.HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings["dbPath"]); OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + str); String strSQL = "SELECT * FROM [reviews] WHERE Host='"+hostname+"'"; OleDbDataAdapter objCmd = new OleDbDataAdapter(strSQL, myConn); DataSet ds = new DataSet(); objCmd.Fill(ds, "reviews"); if (ds.Tables["reviews"].Rows.Count == 0) { string myInsertQuery = "insert into reviews (t-link,t-content) values ('" + TextBox2.Text + "','" + TextBox3.Text + "')"; OleDbCommand myOleDbCommand = new OleDbCommand(myInsertQuery); myOleDbCommand.Connection = myConn; myConn.Open(); myOleDbCommand.ExecuteNonQuery();//显示此行出错。 myConn.Close(); } else { .... } }