问一个初级问题 cmd.ExecuteReader() 怎么老师提示错误 数据库连接也是对的呀!!

StringconnectionString="DataSource=E93D8F816D6343D;InitialCatalog=商品管理;IntegratedSecu... String connectionString = "Data Source=E93D8F816D6343D;Initial Catalog=商品管理;Integrated Security=True";
SqlConnection myconnection = new SqlConnection(connectionString);
myconnection.Open();
string stringsql = "Select * from dbo.商品信息表 where 商品编号= " + idd + "";
SqlCommand cmd = new SqlCommand(stringsql, myconnection);

SqlDataReader sdr = cmd.ExecuteReader(); //就是这里!!!
if (sdr.Read())
{

TextBox2.Text = sdr["name"].ToString();
TextBox3.Text = sdr["number"].ToString();

错误地方:
Line 28:
Line 29:
Line 30: SqlDataReader sdr = cmd.ExecuteReader();
Line 31: if (sdr.Read())
Line 32: {

Source File: d:\QQPCmgr\My Documents\Visual Studio 2010\WebSites\WebSite15\Default3.aspx.cs Line: 30

Stack Trace:

[SqlException (0x80131904): '=' 附近有语法错误。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1950954
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4846939
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
System.Data.SqlClient.SqlDataReader.get_MetaData() +83
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141
System.Data.SqlClient.SqlCommand.ExecuteReader() +89
Default3.Page_Load(Object sender, EventArgs e) in d:\QQPCmgr\My Documents\Visual Studio 2010\WebSites\WebSite15\Default3.aspx.cs:30
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
展开
 我来答
JPG叽叽喳喳
2011-12-14 · TA获得超过308个赞
知道小有建树答主
回答量:202
采纳率:100%
帮助的人:125万
展开全部
把 where 商品编号= " + idd + " 改成 where 商品编号= ‘" + idd + "’
原因idd是字符串要加单引号。
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式