我有个关于asp.net的问题,很急,请哪位高手帮帮忙啊 access很郁闷的注意设置一下数据库的字段 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 以下是向数据库中写入数据的代码,请各位帮帮忙啊using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Data.OleDb;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;namespace test{ /// <summary> /// AddQuestion 的摘要说明。 /// </summary> public class AddQuestion : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox TextBox3; protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.TextBox TextBox4; protected System.Web.UI.WebControls.TextBox TextBox5; protected System.Web.UI.WebControls.TextBox TextBox6; protected System.Web.UI.WebControls.TextBox TextBox7; protected System.Web.UI.WebControls.TextBox TextBox8; protected System.Web.UI.WebControls.TextBox TextBox9; protected System.Web.UI.WebControls.TextBox TextBox10; protected System.Web.UI.WebControls.TextBox TextBox1; protected System.Web.UI.WebControls.TextBox TextBox2; private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 } private string check(string v) { v = v.Replace("'",""); v = Server.HtmlEncode(v); return v; } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void Button1_Click(object sender, System.EventArgs e) { string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;"; string DataBase = Server.MapPath("exam.mdb"); strConnection += "Data Source=" + DataBase; string strSQL = "SELECT * FROM problem where title='" +TextBox1.Text + "'"; OleDbConnection objConnection = new OleDbConnection(strConnection); OleDbCommand objCommand =new OleDbCommand(strSQL, objConnection); OleDbDataReader objDataReader ; objCommand.Connection.Open(); objDataReader = objCommand.ExecuteReader(); if (objDataReader.Read() == true) { Label1.Text = "对不起,问题已存在!"; return;} objCommand.Connection.Close(); string sql = "insert into problem (title,type,ans1,ans2,ans3,ans4,ans5,key_,pub,nandu)values ('" + check(TextBox1.Text) + "','"+ check(TextBox3.Text) + "','"+check(TextBox4.Text)+"','"+check(TextBox5.Text)+"','"+check(TextBox6.Text)+"','"+check(TextBox7.Text)+"','"+check(TextBox8.Text)+"','"+check(TextBox9.Text)+"','"+check(TextBox10.Text)+"','"+check(TextBox2.Text)+"')"; OleDbCommand addCommand =new OleDbCommand(sql, objConnection); addCommand.Connection.Open(); addCommand.ExecuteNonQuery(); addCommand.Connection.Close(); Response.Write ("<script>alert(\"添加成功!\")</script>");return; } } } 如果代码没出问题的话肯定是access数据设置字段的问题了 仔细检查以下》。。 -_-b看不出哪错了。提示你一点,就是access中是int类型的数据,在代码中就不用加''了。 有没有这样的控件呀或样式之类的 谁有wpf和wcf的例子,给我发一份 弹出对话框? 如何自动隐藏已认证用户的Login控件 求救!关于语句写在哪的问题 一个很烦的问题 文本框 记忆功能 问题!! 按钮事件不能响应的问题? 谈谈项目管理的需求 问2个问题,关于DataGrid的嵌套DataGrid 一个AJAX for asp.net 的问题 急问:如何建立数据库连接?
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace test
{
/// <summary>
/// AddQuestion 的摘要说明。
/// </summary>
public class AddQuestion : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.TextBox TextBox5;
protected System.Web.UI.WebControls.TextBox TextBox6;
protected System.Web.UI.WebControls.TextBox TextBox7;
protected System.Web.UI.WebControls.TextBox TextBox8;
protected System.Web.UI.WebControls.TextBox TextBox9;
protected System.Web.UI.WebControls.TextBox TextBox10;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
private string check(string v)
{
v = v.Replace("'","");
v = Server.HtmlEncode(v);
return v;
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;";
string DataBase = Server.MapPath("exam.mdb");
strConnection += "Data Source=" + DataBase;
string strSQL = "SELECT * FROM problem where title='" +TextBox1.Text + "'";
OleDbConnection objConnection = new OleDbConnection(strConnection);
OleDbCommand objCommand =new OleDbCommand(strSQL, objConnection);
OleDbDataReader objDataReader ;
objCommand.Connection.Open();
objDataReader = objCommand.ExecuteReader();
if (objDataReader.Read() == true)
{
Label1.Text = "对不起,问题已存在!";
return;}
objCommand.Connection.Close();
string sql = "insert into problem (title,type,ans1,ans2,ans3,ans4,ans5,key_,pub,nandu)values ('" + check(TextBox1.Text) + "','"+ check(TextBox3.Text) + "','"+check(TextBox4.Text)+"','"+check(TextBox5.Text)+"','"+check(TextBox6.Text)+"','"+check(TextBox7.Text)+"','"+check(TextBox8.Text)+"','"+check(TextBox9.Text)+"','"+check(TextBox10.Text)+"','"+check(TextBox2.Text)+"')";
OleDbCommand addCommand =new OleDbCommand(sql, objConnection);
addCommand.Connection.Open();
addCommand.ExecuteNonQuery();
addCommand.Connection.Close(); Response.Write ("<script>alert(\"添加成功!\")</script>");return;
}
}
}
肯定是access数据设置字段的问题了
仔细检查以下》。。
看不出哪错了。提示你一点,就是access中是int类型的数据,在代码中就不用加''了。