问一个初级问题 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 展开
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 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询