加了单引号也报错:public int AddOneNewsInfo(NewsInfo newsinfo)
{
string sql = String.Format("insert into NewsInfo(UserID,TypeId,NewsTitle,NewsContent,PublishTime,IsAudit,IsPublic) values('{0}',{1},'{2}','{3}','{4}','{5}','{6}')",
newsinfo.UserID,newsinfo.TypeID,newsinfo.NewsTitle,newsinfo.NewsContent,newsinfo.PUblishTIme,newsinfo.IsAudit,newsinfo.IsPublic);
DBHelper db = new DBHelper();
return db.Getcommand(sql);
}protected void btnFabiao_Click(object sender, EventArgs e)
{
bllNewsInfo bll = new bllNewsInfo();
NewsInfo news = new NewsInfo();
//news.UserID = (String)Session["username"];
news.UserID = "湘A88888";
news.TypeID = Int32.Parse(this.ddlNewsType.SelectedValue);
news.NewsTitle = this.txtTitle.Text;
news.NewsContent = this.txtContent.Text;
news.PUblishTIme = DateTime.Now;
news.IsAudit = "是";
news.IsPublic = "是"; int result = bll.AddOneNewsInfo(news);
if (result > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "系统提示", "alert('发表成功!')", true);
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "系统提示", "alert('发表失败!')", true);
} 当UserID为:news.UserID = "湘A 88888";时,报的又是另外一个错:“/WEB”应用程序中的服务器错误。
--------------------------------------------------------------------------------'88888' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: '88888' 附近有语法错误。源错误:
行 43: int result = 0;
行 44: SqlCommand comm = new SqlCommand(sql, Getconnection());
行 45: result = comm.ExecuteNonQuery();
行 46: return result;
行 47: }
{
string sql = String.Format("insert into NewsInfo(UserID,TypeId,NewsTitle,NewsContent,PublishTime,IsAudit,IsPublic) values('{0}',{1},'{2}','{3}','{4}','{5}','{6}')",
newsinfo.UserID,newsinfo.TypeID,newsinfo.NewsTitle,newsinfo.NewsContent,newsinfo.PUblishTIme,newsinfo.IsAudit,newsinfo.IsPublic);
DBHelper db = new DBHelper();
return db.Getcommand(sql);
}protected void btnFabiao_Click(object sender, EventArgs e)
{
bllNewsInfo bll = new bllNewsInfo();
NewsInfo news = new NewsInfo();
//news.UserID = (String)Session["username"];
news.UserID = "湘A88888";
news.TypeID = Int32.Parse(this.ddlNewsType.SelectedValue);
news.NewsTitle = this.txtTitle.Text;
news.NewsContent = this.txtContent.Text;
news.PUblishTIme = DateTime.Now;
news.IsAudit = "是";
news.IsPublic = "是"; int result = bll.AddOneNewsInfo(news);
if (result > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "系统提示", "alert('发表成功!')", true);
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "系统提示", "alert('发表失败!')", true);
} 当UserID为:news.UserID = "湘A 88888";时,报的又是另外一个错:“/WEB”应用程序中的服务器错误。
--------------------------------------------------------------------------------'88888' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: '88888' 附近有语法错误。源错误:
行 43: int result = 0;
行 44: SqlCommand comm = new SqlCommand(sql, Getconnection());
行 45: result = comm.ExecuteNonQuery();
行 46: return result;
行 47: }
解决方案 »
- 服务端 如何保持 Session, 当 HTTP POST
- sqlserver导入导出excel文件
- 什么是“从元数据”啊
- ---高分跪求同时会J2EE和.net2005的人做翻译工作,.net高高手也请看-----
- 请教中文编码方式。
- ASP.NET连接Access数据库刷新几次后出错,请大家帮忙(VB.NET)
- 怎样用asp.net做一个能供手机下载的网站
- 类中域的声明如果没有static等修饰符 默认的修饰符是什么 比如public int tmpint;
- 我修改了datagrid某列编辑框的值,获取之后,存到数据库中的还是原来的,?/
- 初学ASPnet,想通过读取XML获得服务器IP,但是程序执行不成功,请朋友帮忙看看错在哪里
- 请教asp.net C# 的App_Code文件夹里的 *.cs怎么编译成*.DLL,怎么调用?谢谢
- 用标签导出word文档
把生成的SQL语句拷贝下来,放到SQL Server Management Stdio里面运行一下,看报啥错。建议2.
最好把字段名,表名用[]括起来。
行 44: SqlCommand comm = new SqlCommand(sql, Getconnection());
行 45: result = comm.ExecuteNonQuery();
行 46: return result;
行 47: } 你应该在红色的地方下断,看看语句到底是什么,你贴出来的根本不是关键代码。照你的描述,明显是你的语句有错。
---
我发现有不少人不喜欢或者完全不用断点调试。
(在我目前的公司就存在现象:不是不用,而是下了断点也不懂分析)
这种错误用sqlprofile分析更简单,现在提倡尽量不用debug
我为什么调用就不行了啊 调试时sql语句就是那句!
进程:[1836]WebDev.WebServer.EXE源文件与模块生成时的文件不同。仍要让调试器使用它吗?
这是调试时下面的sql语句
在插入数据时加引号,
将保留关键字用方括号括起来,
数据库中字段和插入字段类型不一样,第二个:
把解决方案重新生成一遍,
在网站项目(或视图)->属性页->引用->选中该文件(跟踪不了代码)所在的程序集,移除,重新添加。
string sql = String.Format("insert into NewsInfo(UserID,TypeId,NewsTitle,NewsContent,PublishTime,IsAudit,IsPublic)
values('{0}',{1},'{2}','{3}','{4}','{5}','{6}')",
newsinfo.UserID,newsinfo.TypeID,newsinfo.NewsTitle,newsinfo.NewsContent,newsinfo.PUblishTIme,newsinfo.IsAudit,newsinfo.IsPublic);在这里我是用了 单引号 的啊! 为什么调试的时候里面的sql语句插入值都没用引号括起来呢?
......,'"+car+"',......
ASP.NET WebForm和ASP.NET MVC分页最终解决之道
试下:
string sql = "insert into NewsInfo(UserID,
TypeId,
NewsTitle,
NewsContent,
PublishTime,
IsAudit,
IsPublic)
values('" + newsinfo.UserID + "','"
+ newsinfo.TypeID + "','"
+ newsinfo.NewsTitle + "','"
+ newsinfo.NewsContent + "','"
+ newsinfo.PUblishTIme + "','"
+ newsinfo.IsAudit + "','"
+ newsinfo.IsPublic + "'";