如何把listbox中的数据全写到textbox中
如题,我的需求是listbox中的数据(比如有10条数据)写到textbox里面去(因为我需要把数据横向排列以便打印页面使用),而且我还要把这些数据写到数据库里,应该如何写这个代码呢?
[解决办法]
- C# code
string strValue = "";for(int i = 0; i < this.listBox1.Items.Count; i++){ strValue += this.listBox1.Items[i].ToString();}this.textBox1.Text = strValue;
[解决办法]
- C# code
string s = "";for(int i=0;i<listBox1.Items.Count;i++){ s += listBox1.Items[i].ToString();}textbox.Text = s;
[解决办法]
- C# code
SqlConnection con = new SqlConnection("Data Source=xxx;DataBase=ycw;User ID=sa;PWD=sa");con.Open();SqlCommand cmd = new SqlCommand();cmd.Connection = con;cmd.CommandType = CommandType.Text;cmd.CommandText = "insert into tablename(col) values(@value)";cmd.Parameters.AddWithValue("@value", this.textbox.Text);cmd.ExecuteNonQuery();con.Close();