调试中检查SQL语句
使用 System.Diagnostics.Debug.WriteLine(sSQL);
string sSQL = @"SELECT STEP FROM IMES.M_ROUTE_DETAIL WHERE ROUTE_NAME='" + baseInfo.RouteName + "' AND STATION_TYPE='" + baseInfo.CurrentStationType + "' AND NEXT_STATION_TYPE='" + baseInfo.StationType + "' AND ROWNUM=1";
System.Diagnostics.Debug.WriteLine(sSQL);
dtTemp = utility.Query(sSQL);
return dtTemp;
输出的内容为
SELECT STEP FROM IMES.M_ROUTE_DETAIL WHERE ROUTE_NAME='CVTE' AND STATION_TYPE='Repair' AND NEXT_STATION_TYPE='Repair' AND ROWNUM=1
for循环不符合条件执行下一个不结束循环
关键字:continue
代码
private void btnInput_Click(object sender, EventArgs e)
{
string m_Type = "";
string m_Ipn = "";
string m_Cpn = "";
string m_RellId = "";
string m_MatDesc = "";
string m_VendorCode = "";
string m_VendorName = "";
string m_LotNo = "";
string m_DateCode = "";
string m_SafeNo = "";
string m_ExpDate = "";
string m_Qty = "";
string m_Uom = "";
string sqlstr = "";
if (dgvData.Rows.Count == 0)
{
MessageBox.Show("请先导入数据后再进行保存数据!!!");
return;
}
DataRow[] dataRows = m_dtTable.Select("IPN is not null ");
int iClomnsCount = m_dtTable.Columns.Count;
for (int j = 0; j < dataRows.Length; j++)
{
m_Type = dataRows[j][0].ToString();
m_RellId = dataRows[j][1].ToString();
m_Cpn = dataRows[j][2].ToString();
m_MatDesc = dataRows[j][3].ToString();
m_VendorCode = dataRows[j][4].ToString();
m_VendorName = dataRows[j][5].ToString();
m_LotNo = dataRows[j][6].ToString();
m_DateCode = dataRows[j][7].ToString();
m_SafeNo = dataRows[j][8].ToString();
m_ExpDate = dataRows[j][9].ToString();
m_Qty = dataRows[j][10].ToString();
m_Uom = dataRows[j][11].ToString();
sqlstr = "select * from IMES.P_GLUE_STATUS where SERIAL_NUMBER=:m_RellId ";
object[] sqlparams = new object[] { m_RellId };
DataTable dataTable = utility.Query(sqlstr, sqlparams);
if (dataTable.Rows.Count > 0)
{
MessageBox.Show("RellId:" + m_RellId + "已存在,請确认导入的数据是否正确");
dgvData.Rows[j].DefaultCellStyle.BackColor = Color.Red;
continue;
}
sqlstr = "select * from IMES.M_PART where CPN=:m_Cpn ";
sqlparams = new object[] { m_Cpn };
dataTable = utility.Query(sqlstr, sqlparams);
if (dataTable.Rows.Count < 1)
{
MessageBox.Show("料号:" + m_Cpn + "不存在,請确认导入的数据是否正确");
dgvData.Rows[j].DefaultCellStyle.BackColor = Color.Red;
continue;
}
else
{
for (int i = 0; i < dataTable.Rows.Count; i++)
{
m_Ipn = dataTable.Rows[i]["IPN"].ToString();
}
}
sqlstr = "insert into IMES.P_GLUE_STATUS (SERIAL_NUMBER,GLUE_TYPE,APN,MAT_VENDOR,MAT_BATCH,DATE_CODE,QTY,CPN,CREATE_EMPNO) values " +
"(:m_RellId, :m_Type, :m_Ipn, :m_VendorCode, :m_LotNo, :m_DateCode, :m_Qty, :m_Cpn,:CREATE_EMPNO)";
sqlparams = new object[] { m_RellId, m_Type, m_Ipn , m_VendorCode , m_LotNo, m_DateCode, m_Qty, m_Cpn, utility.GlobalUserNo };
long result = utility.ExecuteSql(sqlstr, sqlparams);
dgvData.Rows[j].DefaultCellStyle.BackColor = Color.Green;
}
MessageBox.Show("資料已上传完成!");
}
跳出循环的几个用法
- return 终止程序
- C# break 语句
当 break 语句出现在一个循环内时,循环会立即终止,且程序流将继续执行紧接着循环的下一条语句。 它可用于终止 switch 语句中的一个 case。 - continue
C# 中的 continue 语句有点像 break 语句。但它不是强迫终止,continue 会跳过当前循环中的代码,强迫开始下一次循环。 对于 for 循环,continue 语句会导致执行条件测试和循环增量部分。对于 while 和 do…while 循环,continue 语句会导致程序控制回到条件测试上。
|