110,535
社区成员
发帖
与我相关
我的任务
分享
string code = txtCode.Text;
string date = txtDate.Text;
string Dep = cmbDep.SelectedValue.ToString();
string Jzcode = cmbJzCode.SelectedValue.ToString();
string JzName = txtJzName.Text;
string ProName = cmbProLName.SelectedValue.ToString();
string ProCompName = cmbCompe.Text;
string LryCode = txtLry.Text;
string LryName = txtLryName.Text;
int i = 0;
for (; i < dgPrint.Rows.Count - 1; i++)
{
string value1 = dgPrint.Rows[i].Cells[0].Value.ToString();
string value2 = dgPrint.Rows[i].Cells[1].Value.ToString();
string value3 = dgPrint.Rows[i].Cells[2].Value.ToString();
string value4 = dgPrint.Rows[i].Cells[3].Value.ToString();
string value5 = dgPrint.Rows[i].Cells[4].Value.ToString();
conn.Open();
string sql = "select count(*) from table_BarcodePrint where Code='" + code + "' and DepartName='" + Dep + "' and JzCode='" + Jzcode + "' and ProLineName='" + ProName + "' and LCMCode='" + value1 + "' and [B/LCode]='" + value2 + "' and CellCode='" + value4 + "' and ZBDCode='" + value4 + "' and ScanDate='"+value5+"'";//判断记录是否存在
SqlCommand comm = new SqlCommand(sql, conn);
if (comm.ExecuteScalar().ToString() == "0")
{
conn.Close();
conn.Open();
string sql1 = "insert into table_BarcodePrint(Code,[Date],DepartName,JzCode,JzName,ProLineName,ProLineCompeName,TempCode,TempName,LCMCode,[B/LCode],CellCode,ZBDCode,ScanDate) " +
"values('" + code + "','" + date + "','" + Dep + "','" + Jzcode + "','" + JzName + "','" + ProName + "','" + ProCompName + "','" + LryCode + "','" + LryName + "','" + value1 + "','" + value2 + "','" + value3 + "','" + value4 + "','" + value5 + "')";
SqlCommand comm1 = new SqlCommand(sql1, conn);
comm1.ExecuteNonQuery();
conn.Close();
}
else
{
conn.Close();
continue;
}
}
string code = txtCode.Text;
string date = txtDate.Text;
string Dep = cmbDep.SelectedValue.ToString();
string Jzcode = cmbJzCode.SelectedValue.ToString();
string JzName = txtJzName.Text;
string ProName = cmbProLName.SelectedValue.ToString();
string ProCompName = cmbCompe.Text;
string LryCode = txtLry.Text;
string LryName = txtLryName.Text;
int i = 0;
try
{
conn.Open();
for (; i < dgPrint.Rows.Count - 1; i++)
{
string value1 = dgPrint.Rows[i].Cells[0].Value.ToString();
string value2 = dgPrint.Rows[i].Cells[1].Value.ToString();
string value3 = dgPrint.Rows[i].Cells[2].Value.ToString();
string value4 = dgPrint.Rows[i].Cells[3].Value.ToString();
string value5 = dgPrint.Rows[i].Cells[4].Value.ToString();
string sql = "select count(*) from table_BarcodePrint where Code='" + code + "' and DepartName='" + Dep + "' and JzCode='" + Jzcode + "' and ProLineName='" + ProName + "' and LCMCode='" + value1 + "' and [B/LCode]='" + value2 + "' and CellCode='" + value4 + "' and ZBDCode='" + value4 + "' and ScanDate='" + value5 + "'";//判断记录是否存在
using (SqlCommand comm = new SqlCommand(sql, conn))
{
if (comm.ExecuteScalar().ToString() == "0")
{
string sql1 = "insert into table_BarcodePrint(Code,[Date],DepartName,JzCode,JzName,ProLineName,ProLineCompeName,TempCode,TempName,LCMCode,[B/LCode],CellCode,ZBDCode,ScanDate) " +
"values('" + code + "','" + date + "','" + Dep + "','" + Jzcode + "','" + JzName + "','" + ProName + "','" + ProCompName + "','" + LryCode + "','" + LryName + "','" + value1 + "','" + value2 + "','" + value3 + "','" + value4 + "','" + value5 + "')";
comm.CommandText = sql1;
comm.ExecuteNonQuery();
}
}
}
}
catch (Exception ex)
{
// 这里加上你要显示给用处的错误信息,比如弹个框什么的
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}