'dbo' 附近有语法错误

zhyy452 2010-12-27 08:25:58
请教各位高手:
存储过程是这样的:
ALTER PROCEDURE dbo.StoredProcedure1
(
@客户ID nvarchar(20),
@产品ID int,
@产品名称 nvarchar(40),
@单位数量 nvarchar(20),
@单价 numeric (18,2),
@订购量 int,
@订购时间 dateTime
)
AS
/* SET NOCOUNT OFF;*/
INSERT INTO dbo.订单表(客户ID,产品ID,产品名称,单位数量,单价,订购量,订购时间)
VALUES (@客户ID,@产品ID,@产品名称,@单位数量,@单价,@订购量,@订购时间)
RETURN
存入订单的代码如下:
protected void Button2_Click(object sender, EventArgs e)
{
for (int ii = 0; ii < GridView1.Rows.Count; ii++)
{
CheckBox cc = (CheckBox)GridView1.Rows[ii].Cells[0].FindControl("CheckBox1");
if (cc.Checked)
{
SqlDataSource1.InsertParameters.Clear();
SqlDataSource1.InsertParameters.Add("客户ID",Session["khbj"].ToString());
SqlDataSource1.InsertParameters.Add("产品ID",GridView1.Rows[ii].Cells[1].Text);
SqlDataSource1.InsertParameters.Add("产品名称",GridView1.Rows[ii].Cells[2].Text);
SqlDataSource1.InsertParameters.Add("单位数量", GridView1.Rows[ii].Cells[3].Text);
SqlDataSource1.InsertParameters.Add("单价", GridView1.Rows[ii].Cells[4].Text);
SqlDataSource1.InsertParameters.Add("订购量", GridView1.Rows[ii].Cells[5].Text);
SqlDataSource1.InsertParameters.Add("订购时间",DateTime.Today.ToShortDateString());
SqlDataSource1.InsertCommand = "dbo.StoredProcedure1";
Session["ccsj"] = DateTime.Today.ToShortDateString();
SqlDataSource1.Insert();
}

}
}
出现这样的错误:
'dbo' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Data.SqlClient.SqlException: 'dbo' 附近有语法错误。

源错误:


行 56: SqlDataSource1.InsertCommand = "dbo.StoredProcedure1";
行 57: Session["ccsj"] = DateTime.Today.ToShortDateString();
行 58: SqlDataSource1.Insert();
行 59: }
行 60:


源文件: f:\0815020124张燕燕\role\结账.aspx.cs 行: 58

堆栈跟踪:


[SqlException (0x80131904): 'dbo' 附近有语法错误。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +177
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +68
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +199
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2300
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +147
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1021
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +314
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +413
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +115
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +392
System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +405
System.Web.UI.WebControls.SqlDataSource.Insert() +13
结账.Button2_Click(Object sender, EventArgs e) in f:\0815020124张燕燕\role\结账.aspx.cs:58
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +97
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4921




该怎么解决呢?
...全文
330 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
chen_ya_ping 2010-12-27
  • 打赏
  • 举报
回复
对于你的存储过程,你可以先在你的数据库中执行一下看看对不对。
zhyy452 2010-12-27
  • 打赏
  • 举报
回复
通过去掉dbo.,重新检查数据类型,再加上在insertcommandtype中设置为StoredProcedure,成功啦!
一晚上也过去了。。。
koukoujiayi 2010-12-27
  • 打赏
  • 举报
回复
代码没什么错!一般是数据类型有问题:
检查一下数据是否是数字?
...("产品ID",GridView1.Rows[ii].Cells[1].Text);
...("单位数量", GridView1.Rows[ii].Cells[3].Text);
...("单价", GridView1.Rows[ii].Cells[4].Text);
...("订购量", GridView1.Rows[ii].Cells[5].Text);
叶子 2010-12-27
  • 打赏
  • 举报
回复
create PROCEDURE StoredProcedure1
存储过程名字不要前面的dbo.

62,240

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧