我想把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')";
}
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')";
}
解决方案 »
- 有比较数组大小的函数 谢谢 在线等 立马给分
- 关于c#开发GUI比c++使用MFC简单的问题
- C# GSM 长短信开发 俺用wavecome 的猫猫 有例子的最好主要是长短信的发送问题搞不掂不够再加分
- 如何在KeyPress事件中判断是否按下方向键?
- 一个简单的问题帮我解决下
- 为什么无法触发OnKeyPress和OnKeyDown方法?
- 删除Menu的问题,哪一题正确?
- c#怎么获取access中的数据以用于计算
- 我安装好了VS。NET 2003 也安装了MSDN 可是打开帮助之后什么也没有?
- Xml文件可以绑定到DataGrid吗?
- 动态改变IE代理服务器地址 顶者有分
- 在C#中怎样屏蔽Alt+Tab,Win,Ctrl+Esc键~~~~~~~~~``急!!!!
2。 使用了未赋值的局部变量“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')";
}
{
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 + ... ,是写错了吧