还是无法将添加的内容写入到数据库,怎么办??
ayaye 2007-04-14 06:44:30 运行界面是正常的,但是一些内容提交时就出现下面这个问题,为什么呢??
请帮帮忙,谢谢了!!
第 1 行: 'value' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: 'value' 附近有语法错误。
源错误:
行 71: Conn.Open();
行 72:
行 73: addcommand.ExecuteNonQuery();
行 74:
行 75: Conn.Close();
源文件: c:\inetpub\wwwroot\views\添加视频.aspx.cs 行: 73
using System.Data.SqlClient;
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;
namespace views
{
/// <summary>
/// 添加视频 的摘要说明。
/// </summary>
public class 添加视频 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox TB1;
protected System.Web.UI.WebControls.TextBox TB2;
protected System.Web.UI.WebControls.RequiredFieldValidator RFV1;
protected System.Web.UI.WebControls.RequiredFieldValidator RFV2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label4;
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.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 connstr="server=127.0.0.1;database=aspnet;uid=sa;pwd=123123";
string strsql="select count(*)from VideoInfo where VideoID like'"+TB1.Text+"'";
SqlConnection Conn=new SqlConnection(connstr);
SqlCommand mycommand=new SqlCommand(strsql,Conn);
Conn.Open();
int flag=(int)mycommand.ExecuteScalar();
Conn.Close();
if(flag==0)
{
string selectstr="insert into VideoInfo(VideoID,VideoAdd)value('"+TB1.Text+"','"+TB2.Text+"',getdate())";
SqlCommand addcommand=new SqlCommand(selectstr,Conn);
Conn.Open();
addcommand.ExecuteNonQuery();
Conn.Close();
Session["VideoID"]=TB1.Text;
Label4.Text="添加成功!";
}
else
{
Label4.Text="错误,请重试!";
TB1.Text="";
TB2.Text="";
}
}
}
}