0

从数据库表接收列值时,我正在应用拆分函数。我想在button_click事件发生时继续这个过程。

这是我的 C# 代码。

protected void Button2_Click(object sender, EventArgs e)
{
      string st = "SELECT F_L FROM split_master";
      cmd = new SqlCommand(st, sqlcon);
      int count = 0;
      string[] word = st.Split();
      for (count = 0; count <= word.Length - 1; count++)
      {
          MessageBox.Show(word[count]);
      }
      cmd.Connection.Open();
      cmd.ExecuteNonQuery();
      cmd.Connection.Close();
}

请帮忙。

4

1 回答 1

0

试试这个代码:

 protected void Button2_Click(object sender, EventArgs e)
 {
    string st = "SELECT F_L FROM split_master";
    cmd = new SqlCommand(st, sqlcon);
    cmd.Connection.Open();
    SqlDataReader sqlread = cmd.ExecuteReader();
    cmd.Connection.Close();
    while(sqlread.Read()){
        string[] word = sqlread["F_L"].ToString().Split();
        for (int count = 0; count <= word.Length; count++)
        {
            MessageBox.Show(word[count]);
        }
    }
  }
于 2014-08-16T05:55:22.373 回答