private void button1_Click(object sender, System.EventArgs e)
{
//点击查找,在数据集中显示查找内容
 selectype = selectype.Text; 
 keyword = keyword.Text;
cmdGetAll.Parameters["@selectype"].Value = selectype;
cmdGetAll.Parameters["@keyword"].Value = keyword;
sqlConnection1.Open();
System.Data.SqlClient.SqlDataAdapter dr;
dr = cmdGetAll.ExecuteReader(CommandBehavior.SingleRow);

songno.Text = ( string )dr["songno"];
   songname.Text = ( string )dr["songname"];
singer.Text = ( string )dr["singer"];
songdate.Text = ( string )dr["songdate"];
dr.close;
sqlConnection1.Close;
}

解决方案 »

  1.   

    问题1    
    dsongname.Text = ( string )dr["songname"];无法将带 [] 的索引应用于“System.Data.SqlClient.SqlDataAdapter”类型的表达式问题2
    selectype = selectype.Text;
    无法将类型“string”隐式转换为“System.Windows.Forms.ComboBox”问题3
    dr = cmdGetAll.ExecuteReader(CommandBehavior.SingleRow);
     无法将类型“System.Data.SqlClient.SqlDataReader”隐式转换为“System.Data.SqlClient.SqlDataAdapter”
    先谢谢
      

  2.   

    大致情况 我想用select * from alldb where @selectype = @keyword 找数据库的内容。
    keyword ,selectype 是两参数。从两控件ComboBox(name:selectype ),textbox(name:keyword )传值得到数据。问题2 
    无法将类型“string”隐式转换为“System.Windows.Forms.ComboBox”我本来想把selectype.Text 传给 参数selectype其中selectype是个ComboBox控件。
    小弟不知道selectype.Text 是不是string型?
    请问要这样才能把值传过去。
    我要怎样改。
      

  3.   

    1.你定义的dr出错了,应该是System.Data.SqlClient.sqlDataReader,那样才可以用下面的ExecuteReader()函数
    2.selectype.Text 是string类型的,selectype应该是comboBox的ID吧
    3.同一,如果解决了一的话应该不存在这个问题了
      

  4.   

    selecttype.Text.toString()就是string类型了。
      

  5.   

    问题2
    lovvver(春晖) 的方法不行。
    到底怎样才能把ComboBox,TextBox控件的值传到一个变量啊?
      

  6.   

    回tf_king(小不点!!) 我是在写windows程序不是web。所以selectype是name不是ID.
      

  7.   

    你这样试一试吧:private void button1_Click(object sender, System.EventArgs e)
    {
    //点击查找,在数据集中显示查找内容  selectype = selectype.SelectedItem.ToString(); 
     keyword = keyword.Text
    .......................
    }
      

  8.   

    楼主的代码有一些像VB又有一点像C#..   :)System.Data.SqlClient.SqlDataAdapter dr;
    --->
    System.Data.SqlClient.SqlDataReader dr;
    songno.Text = ( string )dr["songno"];
       songname.Text = ( string )dr["songname"];
    singer.Text = ( string )dr["singer"];
    songdate.Text = ( string )dr["songdate"];
    dr.close;
    sqlConnection1.Close;
    --->dr.Read();
    dr["songname"].ToString();
    dr.Close();
    sqlConnection1.Close();
      

  9.   

    你想把查找的结果选出来.来什么要用
    CommandBehavior.SingleRow??
    这是什么意思呀?
    只选出一行??
    dr = cmdGetAll.ExecuteReader();