using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;namespace WebApplication1
{
/// <summary>
/// _default 的摘要说明。
/// </summary>
public class _default : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Button btnok;
protected System.Web.UI.WebControls.TextBox tbzhuti;
protected System.Web.UI.WebControls.TextBox tbmemo;
protected System.Web.UI.WebControls.Button btncancel;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnok.Click += new System.EventHandler(this.btnok_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void btnok_Click(object sender, System.EventArgs e)
{
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" +Server.MapPath("lyb.mdb");
string strSQL = "insert into gb(zhuti,memo) values('" +tbzhuti.Text.ToString()+ "','" +tbmemo.Text.ToString+ "')";
OleDbConnection objConnection=new OleDbConnection(strConnection);
OleDbCommand objCommand = new OleDbCommand(strSQL , objConnection);
objCommand.Connection.Open();
objCommand.ExecuteNonQuery();
objConnection.Close(); }
}
}
请问为什么个添加了,向数据库里的插入数据的功能,我在浏览网页的时候,确不能把用户输入的信息加入到数据库里呢?
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;namespace WebApplication1
{
/// <summary>
/// _default 的摘要说明。
/// </summary>
public class _default : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Button btnok;
protected System.Web.UI.WebControls.TextBox tbzhuti;
protected System.Web.UI.WebControls.TextBox tbmemo;
protected System.Web.UI.WebControls.Button btncancel;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnok.Click += new System.EventHandler(this.btnok_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void btnok_Click(object sender, System.EventArgs e)
{
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" +Server.MapPath("lyb.mdb");
string strSQL = "insert into gb(zhuti,memo) values('" +tbzhuti.Text.ToString()+ "','" +tbmemo.Text.ToString+ "')";
OleDbConnection objConnection=new OleDbConnection(strConnection);
OleDbCommand objCommand = new OleDbCommand(strSQL , objConnection);
objCommand.Connection.Open();
objCommand.ExecuteNonQuery();
objConnection.Close(); }
}
}
请问为什么个添加了,向数据库里的插入数据的功能,我在浏览网页的时候,确不能把用户输入的信息加入到数据库里呢?
看看你的SQL是否真确
这是无效转换,实际并不执行tbzhuti.Text即可
{
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" +Server.MapPath("lyb.mdb");
string strSQL = "insert into gb(zhuti,memo) values('" +tbzhuti.Text.ToString()+ "','" +tbmemo.Text.ToString()+ "')";
OleDbConnection objConnection=new OleDbConnection(strConnection);
objConnection.Open();
OleDbCommand objCommand = new OleDbCommand(strSQL , objConnection);
objCommand.ExecuteNonQuery();
objConnection.Close(); }
{
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" +Server.MapPath("lyb.mdb");
string strSQL = "insert into gb(zhuti,memo) values('" +tbzhuti.Text.ToString()+ "','" +tbmemo.Text.ToString+ "')";
上面的代码有处错误,应该是tbmemo.Text.ToString(),你的
tbmemo.Text看样子应该是个文本框,如果这样的话就不用.ToString()了,它不起作用的