Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.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
Switch语句C#使用MYSQL数据库中的数据_C#_Mysql_Asp.net_Switch Statement - Fatal编程技术网

Switch语句C#使用MYSQL数据库中的数据

Switch语句C#使用MYSQL数据库中的数据,c#,mysql,asp.net,switch-statement,C#,Mysql,Asp.net,Switch Statement,好的,我在MYSQL数据库中有一个列,这个列名为specie,其中有狗、猫和兔子。 然后,我有一个下拉列表,其中填充了specie中的数据。我需要一个switch语句,它将为每个选定的宠物显示一个标签。 e、 g.如果用户选择兔子,兔子的价格为£00.00 这是我的下拉列表代码 public partial class _Default : Page { DataSet ds = new DataSet(); MySqlConnection cs = new MySqlCon

好的,我在MYSQL数据库中有一个列,这个列名为
specie
,其中有狗、猫和兔子。 然后,我有一个下拉列表,其中填充了
specie
中的数据。我需要一个
switch语句
,它将为每个选定的宠物显示一个
标签
。 e、 g.如果用户选择兔子,兔子的价格为£00.00

这是我的下拉列表代码

 public partial class _Default : Page
{

    DataSet ds = new DataSet();
    MySqlConnection cs = new MySqlConnection(@"SERVER= 000.000.00.000;username=*****;password=*****; Initial Catalog = mydb");
    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();
    }

我假设数据库中也存储了每种动物的成本。 如果是这样,我会这样做:

  • 像当前一样填充下拉列表
  • 在.NET中,您可以指定AutoPostBack=“true”和onSelectedIndexChanged=“someMethod”。前者将在下拉更改时发回服务器,后者将调用“someMethod”
  • 然后,这种“someMethod”可以在数据库中查找所选物种的成本,并填充标签

  • 有意义吗?

    我可以用mysql数据库中的数据做一个switch语句吗?很抱歉,我没有数据库中的值,我现在就做一个名为Cost的行,然后试着回答。谢谢你如果这个答案对你有效,请接受它作为正确答案和/或投票。谢谢。我会的。我现在就试试。很抱歉我的回复太晚了,好吧,我已经自动回邮了,还做了一个叫做“ChosenAnimal”的SelectMethod,还在我的表格中做了一个叫做“PetMindNation”的专栏。我该如何写一份声明来查找这个物种?你是什么意思?SQL语句?