如果用VS。NET,创建连接,拖到页面即可
解决方案 »
- 一名优秀的asp.net程序员所需要掌握的技能有哪些
- ASP.NET中TreeView在网页框架中跳转页面的问题
- 关于控制文件下载的问题
- ***发现导分的了,还是个星星呢,快来看看吧,我已经向版主举报了,就看版主是怎么办的了。
- 求匹配<img ....></img> 的正则表达式
- 求在线统计的做法及代码
- 难,请问一条SQL语句,查询出两个表的相关内容,如何在一个DATAGRID中现实
- 验证控件问题?
- 各个节在每个配置文件中必须只出现一次
- 在datagird生成的table中如何指定td的width,height,bgcolor等属性?
- Datagrid 问题,为什么我按下一页到第二页就翻不下去了?
- 有关 asp.net 开发网站的问题,请高手指点
那样,有快,也比这个好
System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
this.con = new System.Data.OleDb.OleDbConnection();
this.cmdGetDetails = new System.Data.OleDb.OleDbCommand();
this.btnAdd.Click += new System.Web.UI.ImageClickEventHandler(this.btnAdd_Click);
//
// con
//
this.con.ConnectionString = ((string)(configurationAppSettings.GetValue("con.ConnectionString", typeof(string))));
//
// cmdGetDetails
//
this.cmdGetDetails.CommandText = "SELECT Large_Image, Code, Description, Chi_Description, Details, Chi_Details FROM" +
" Inv_Stock_Masters WHERE (ID = ?)";
this.cmdGetDetails.Connection = this.con;
this.cmdGetDetails.Parameters.Add(new System.Data.OleDb.OleDbParameter("ID", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)), "ID", System.Data.DataRowVersion.Current, null));
this.Load += new System.EventHandler(this.Page_Load); }
改为:
private void InitializeComponent()
{
System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
this.con = new System.Data.SqlClient.SqlConnection();
this.cmdGetDetails = new System.Data.SqlClient.SqlCommand();
this.btnAdd.Click += new System.Web.UI.ImageClickEventHandler(this.btnAdd_Click);
//
// con
//
this.con.ConnectionString = ((string)(configurationAppSettings.GetValue("con.ConnectionString", typeof(string))));
//
// cmdGetDetails
//
this.cmdGetDetails.CommandText = "SELECT Image_2, Code, Description, Chi_Description FROM" +
" Inv_Stock_Masters WHERE (ID = ?)";
this.cmdGetDetails.Connection = this.con;
this.cmdGetDetails.Parameters.Add(new System.Data.SqlClient.SqlParameter("ID", System.Data.SqlDbType .Int, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)), "ID", System.Data.DataRowVersion.Current, null));
this.Load += new System.EventHandler(this.Page_Load); }
错误信息:
第 1 行: 'ID' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: 'ID' 附近有语法错误。源错误:
行 89: {
行 90: con.Open();
行 91: rd = cmdGetDetails.ExecuteReader(CommandBehavior.CloseConnection);
行 92: if (rd.Read())
行 93: {
源文件: d:\pacificportal\product_details.aspx.cs 行: 91 堆栈跟踪:
[SqlException: 第 1 行: 'ID' 附近有语法错误。]
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +643
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) +9
PacificPortal.Product_Details.LoadData() in d:\pacificportal\product_details.aspx.cs:91
PacificPortal.Product_Details.Page_Load(Object sender, EventArgs e) in d:\pacificportal\product_details.aspx.cs:78
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +29
System.Web.UI.Page.ProcessRequestMain() +724
--------------------------------------------------------------------------------
版本信息: Microsoft .NET 框架版本:1.0.3705.0; ASP.NET 版本:1.0.3705.0
this.cmdGetDetails.Parameters.Add(new SqlParameter("@paramID", SqlDbType.Integer);应该是参数名写错了。
string="data source=数据库机器名;uid=用户名;pwd=密码;database=数据库名"