我想把ListBox 里面的数据都添加到数据库去,我用下面的代码,目的是想把它们都放在一个SQL里然后执行,请问题我这样做那里有问题?或者说那位高手有更好的办法?谢谢!
foreach(ListItem li in ListBox2.Items)
{
  strsqlf+=strsqlf + "insert into ofl_file(ofl01,ofl02,ofl03,ofldate)values('" + TextBox2.Text.ToString() + "','" + ListBox2.Items.ToString() + "','" + ListBox2.Items.ToString().Substring(3,2) + "','today')"; 
}

解决方案 »

  1.   

    1。 声明了变量“li”,但从未使用过
    2。 使用了未赋值的局部变量“strsqlf”出现两个这样的错!
      

  2.   

    string strsqlf = "";
    for(int i=0;i<=this.ListBosx.Items.Count-1;i++)
      {
    strsqlf += "insert into ofl_file(ofl01,ofl02,ofl03,ofldate)values('" 
             + TextBox2.Text.ToString() + "','" + ListBox2.Items.ToString()             
             + "','" + ListBox2.Items[i].ToString().Substring(3,2) + "','today')"; 
      }
      

  3.   

    foreach(ListItem li in ListBox2.Items)
    {
      strsqlf+=strsqlf + "insert into ofl_file(ofl01,ofl02,ofl03,ofldate)values('" + TextBox2.Text.ToString() + "','" + ListBox2.Items.ToString() + "','" + ListBox2.Items.ToString().Substring(3,2) + "','today')"; 
    }1。 声明了变量“li”,但从未使用过
    foreach(ListItem li in ListBox2.Items)
    {
    这里本来就没有用li啊,不过这应该是一个警告,没什么问题
    }
    使用了未赋值的局部变量“strsqlf”
    变量使用前要声明的....还有strsqlf+=strsqlf + ...     ,是写错了吧