try
{
if (txtDesc1.Text == "")
{
}
else
{
con1 = new SqlDbConnect();
strSQL = "insert into sample (id, description, dosage, qty, selling, amount)";
strSQL += "select '" + labelTransID.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtDesc1.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtDosage1.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtQty1.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtSelling1.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtAmount1.Text.Replace("'", "''") + "'";
con1.SqlQuery(strSQL);
con1.NonQueryEx();
con1.Close();
}
if (txtDesc2.Text == "")
{
}
else
{
con2 = new SqlDbConnect();
strSQL = "insert into sample (id, description, dosage, qty, selling, amount)";
strSQL += "select '" + labelTransID.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtDesc2.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtDosage2.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtQty2.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtSelling2.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtAmount2.Text.Replace("'", "''") + "'";
con2.SqlQuery(strSQL);
con2.NonQueryEx();
con2.Close();
}
if (txtDesc3.Text == "")
{
}
else
{
con3 = new SqlDbConnect();
strSQL = "insert into sample (id, description, dosage, qty, selling, amount)";
strSQL += "select '" + labelTransID.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtDesc3.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtDosage3.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtQty3.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtSelling3.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtAmount3.Text.Replace("'", "''") + "'";
con3.SqlQuery(strSQL);
con3.NonQueryEx();
con3.Close();
}
if (txtDesc4.Text == "")
{
}
else
{
con4 = new SqlDbConnect();
strSQL = "insert into sample (id, description, dosage, qty, selling, amount)";
strSQL += "select '" + labelTransID.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtDesc4.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtDosage4.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtQty4.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtSelling4.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtAmount4.Text.Replace("'", "''") + "'";
con4.SqlQuery(strSQL);
con4.NonQueryEx();
con4.Close();
}
if (txtDesc5.Text == "")
{
}
else
{
con5 = new SqlDbConnect();
strSQL = "insert into sample (id, description, dosage, qty, selling, amount)";
strSQL += "select '" + labelTransID.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtDesc5.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtDosage5.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtQty5.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtSelling5.Text.Replace("'", "''") + "'";
strSQL += ", '" + txtAmount5.Text.Replace("'", "''") + "'";
con5.SqlQuery(strSQL);
con5.NonQueryEx();
con5.Close();
}
}
catch
{
MessageBox.Show("Successfully Saved", "Completed !", MessageBoxButtons.OK);
}
here is my code for saving...problem is when the other textboxes are empty. won't save to sql database. is there any other approach to minimize this lot of codes.ty