【问题标题】:DataAdapter overloaded method errorDataAdapter 重载方法错误
【发布时间】:2014-09-17 06:40:52
【问题描述】:

下面我提到了我的 dropdonlist 代码。 SqlDataAdapter sda = new SqlDataAdapter(str2) 字段显示一些无效的重载方法,我正在使用单独的类进行连接。有人帮我解决错误 conn=sqlconnection(单独的类)。 query=function 用于“选择”方法。

protected void fill2()
{             
           string str1 = "select CompanyID from Company where CompanyName='" + ddcompany.SelectedItem.Text + "'";
           SqlDataReader dr2 = conn.query(str1);
           if (dr2.Read())
           {
               string id1 = dr2[0].ToString();

               string str = "select ZoneID  from Zone where Zone='" + ddzone.SelectedItem.Text + "' and CompanyID='" + id1 + "'";
               SqlDataReader dr1 = conn.query(str);
               if (dr1.Read())
               {
                   string id = dr1[0].ToString();
                   string str2 = "select Region from Region where ZoneID='" + id + "'";
                   SqlDataAdapter sda = new SqlDataAdapter(str2);
                   DataTable dt = new DataTable();
                   sda.Fill(dt);
                   ddregion.DataSource = dt;
                   ddregion.DataBind();


               }

【问题讨论】:

  • 什么是:conn.query(str1);? conn = SqlConnection ??这个没有名为查询的方法...
  • @Edi G.Conn=sqlconnection。它是单独的连接类,查询是选择类

标签: c#


【解决方案1】:

SQLDataAdapter 中没有带有 para SqlDataAdapter(string query) 的构造函数

改变这个:

SqlDataAdapter sda = new SqlDataAdapter(str2);

对此:

SqlDataAdapter sda = new SqlDataAdapter(str2, conn);

More Information

顺便说一句。您的代码并不是真正的最佳实践.. Basic example

【讨论】:

  • G.yes 我检查了示例,它只是从表中选择所有员工,但在我的情况下,我必须找到 CompanyID、Zone ID 和区域。
  • 你的 conn 对象是 SqlConnection 对象吗?
  • @Edi G. 是的,这是我的连接对象
  • jap.. 这是问题.. 它是您的连接对象。 SqlDataReader 需要一个 SqlConnection 对象 (System.Data.SqlClient.SqlConnection)
猜你喜欢
  • 1970-01-01
  • 2012-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多