Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C#switch语句中使用MYSQL中的数据_C#_Mysql_Asp.net_Switch Statement - Fatal编程技术网

在C#switch语句中使用MYSQL中的数据

在C#switch语句中使用MYSQL中的数据,c#,mysql,asp.net,switch-statement,C#,Mysql,Asp.net,Switch Statement,如何根据从下拉列表中选择的数据获取标签(打印) 到目前为止的代码 public partial class _Default : Page { DataSet ds = new DataSet(); MySqlConnection cs = new MySqlConnection(@"SERVER= ***.***.**.***;username=*****;password=***; Initial Catalog = dbname");

如何根据从下拉列表中选择的数据获取标签(打印)

到目前为止的代码

public partial class _Default : Page
    {

        DataSet ds = new DataSet();
        MySqlConnection cs = new MySqlConnection(@"SERVER= ***.***.**.***;username=*****;password=***; Initial Catalog = dbname");
        MySqlDataAdapter da = new MySqlDataAdapter();

        protected void Page_Load(object sender, EventArgs e)
        {
            MySqlCommand cd = new MySqlCommand("SELECT * FROM pets", cs);
            cs.Open();
            MySqlDataReader ddl = cd.ExecuteReader();
            DdPetPist.DataSource = ddl;
            DdPetPist.DataValueField = "Specie";
            DdPetPist.DataTextField = "Specie";
            DdPetPist.DataBind();
            cs.Close();
            cs.Dispose();
        }

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            MySqlCommand cd = new MySqlCommand("SELECT CAST(Specie AS varchar) + '#' + CAST(Specie_Price AS varchar) AS Specie FROM pets");

        }  

因此,我需要的是,如果选择了Dog from下拉列表,标签上写着Dog is£20,如果cat£30,那么我知道我需要一个switch语句,但我不确定如何使用数据库中的数据当您在page_load中处理mysqlconnection时,您会将其断开,以便稍后在请求中与其他事件一起使用,例如您的selectedindex changed事件。您应该为数据库的每次调用创建一个新的mysqlconnection对象。此外,您应该确保您的结束通话是
finally
块的一部分。谢谢您的建议。