需要从RTB中的表中获取数据

时间:2011-05-05 11:51:13

标签: c# xml content-management-system

好的,我有两张桌子:

内容 - >在combobox中显示,名为cntpaginaBX。

促销 - >在组合框中显示名为prmopaginaBX。

当我从rtb中显示的内容中选择一个项目时:我得到了以下代码,但它不起作用。

    private void cntpaginaBX_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (cntpaginaBX.SelectedItem == "Welkom")
        {
            MySqlConnection sqlConn = new MySqlConnection("Database=joshua; Data Source=localhost; User Id='root'; Password=''");
            string content = "SELECT * FROM content WHERE title=Welkom";
            MySqlCommand myCommando = new MySqlCommand(content, sqlConn);
            MySqlDataReader sqlReader;
            object welkom;


            try
            {
                sqlConn.Open();                    
                sqlReader = myCommando.ExecuteReader();
                while (sqlReader.Read())
                {
                    welkom = sqlReader.GetValue(0).ToString();
                    showText.Text = welkom.ToString();

                }
                sqlReader.Close();
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message, "Fout", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                sqlConn.Close();
            }
        }
    }

0 个答案:

没有答案