如果用VS。NET,创建连接,拖到页面即可

解决方案 »

  1.   

    你的数据库连接字符串是在哪定义的,更改成与sqlserver的连接即可。
      

  2.   

    是否忘记指定链接到SQL Server时登陆的数据库,可能转到了默认数据库master了,所以没有找到你需要的表。
      

  3.   

    我不明白你为什么不用SQL server.NET提供的方法重新写一个连接过程。
    那样,有快,也比这个好
      

  4.   

    源程序段:
    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 
      

  5.   

    你只用把所有的OleDb改为SqlData
      

  6.   

    "ID"换成"[ID]"ID在SQL Server里面是关键字
      

  7.   

    你需要把?改为@paramID
    this.cmdGetDetails.Parameters.Add(new SqlParameter("@paramID", SqlDbType.Integer);应该是参数名写错了。
      

  8.   

    把你的连库字符串改成:
    string="data source=数据库机器名;uid=用户名;pwd=密码;database=数据库名"