想在数据库删除语句中调用listBox空间中的文本内容,但不知道该如何取出此控件中的文本内容,指教!
如textBox1.Text,类似于此文本信息

解决方案 »

  1.   

    string str = listBox1.Items[i].ToString();
      

  2.   

    比如取出当前选中的项的文本内容:if (this.listBox1.SelectedItem != null)
                {
                    //比如取出来放到TextBox中
                    this.textBox1.Text = this.listBox1.SelectedItem.ToString();
                }
      

  3.   

    不好意思,我换一个问题,listBox2.Text好像取出文本内容,可能是我的数据库执行语句写错了,我的代码
    string strconn;
    strconn="data source=(local);initial catalog=student_pl;Integrated Security=SSPI;";
    SqlConnection cn1=new SqlConnection(strconn);
    cn1.Open();
    string s = "delete  from score where cname = '"+listBox2.Text+"'";
    SqlCommand cmd1=new SqlCommand();
    cmd1.Connection=cn1;
    cmd1.CommandText=s;
    cmd1.ExecuteNonQuery();执行后,数据库中并没有删除我想删除的纪录,是哪个地方错了呢,请指教
      

  4.   

    如果想取出指定的某项:            //比如取出第一项
                this.textBox1 .Text =this.listBox1.Items[0].ToString();
      

  5.   

    TO:strconn="data source=(local);initial catalog=student_pl;Integrated Security=SSPI;";
    或者你最好用sa用户试下..for example:strconn="server=.;database=student_pl;uid=sa;pwd=密码";因为以前我用windows身份验证登录的时候也碰到过这样的问题,你用sa用户先试下吧.