怎么把listbox中的项插入到数据库

来源:百度知道 编辑:UC知道 时间:2024/06/17 05:52:44

SqlConnection Conn= …… //你的数据库连接
Conn.Open();
for (int i = 0; i < listBox1.Items.Count; i++)
{
string sql="insert into #yourtable (字段名) values (listBox1.Items[i].ToString())";
SqlCommand Cmd = new SqlCommand(sql, Conn);
Cmd.ExecuteNonQuery();
}
Conn.Close();