为什么我用Substring第一次可以截取到我想要的数据第二次就不行了
while (txt != null)
{
txt = sr.ReadLine();
if (txt != null)
{
sql = " select DirSirOrder_NO from T_DirSirOrder where DirSirOrder_NO='" + txt.Substring(0, txt.IndexOf(',')) + "'";
dtRow = ShineBLL.GetSingle(sql);
if (dtRow != null)
{
MessageBox.Show("数据已重复,请先查看数据!");
sr.Close();
sr.Dispose();
return;
}
sql1 = "select Prd_NO from A_PrdBase where Prd_NO='" + txt.Substring(15, txt.IndexOf(',')) + "'";
dtRow = ShineBLL.GetSingle(sql1);
if (dtRow == null)
{
//MessageBox.Show("发现非法商品,请查看数据!");
sw.WriteLine(txt);
//return;
}
[解决办法]
用Split切割成数组就是了。
string[] arr = txt.Split(',');
sql = " select DirSirOrder_NO from T_DirSirOrder where DirSirOrder_NO='" + arr[0] + "'";
...
sql1 = "select Prd_NO from A_PrdBase where Prd_NO='" + arr[1] + "'";