I got a situation here. I need to insert values into tables depending on what a user provides on the Window form. If a good does not exist and more than is necessary is acquired the the excess must be entered into a table called "BulkAvailable" this is where a big exists in my code as when I comment this part out the code runs well. Please find the piece of code below
try
{
SqlConnection con = new SqlConnection("Data Source=PV10\\LOCALSERVER;Initial Catalog=SmallSoftwareDB;Integrated Security=True;Pooling=False");
con.Open();
float a = float.Parse(textBox8.Text, System.Globalization.CultureInfo.InvariantCulture);
int b = int.Parse(textBox9.Text);
float c = a * b;
var T = c.ToString(System.Globalization.CultureInfo.InvariantCulture);
float x = float.Parse(textBox4.Text, System.Globalization.CultureInfo.InvariantCulture);
int z = int.Parse(textBox3.Text);
float y = x * z;
var total = y.ToString(System.Globalization.CultureInfo.InvariantCulture);
int d = b - z;
string uba = "insert into BulkSale(ProductName, ProductSource, Date, Quantity, Type, UnitPrice, Total, Nature) values('" + textBox1.Text + "', '" + textBox2.Text + "', '" + dateTimePicker1.Value + "', '" + textBox3.Text + "', '" + textBox6.Text + "', '" + textBox4.Text + "', '" + textBox5.Text + "', '"+textBox7.Text+"')";
string A = "insert into BulkInput(ProductName, ProductSource, Date, Quantity, Type, UnitPrice, Total, Nature) values('"+textBox1.Text+"','"+textBox2.Text+"','"+dateTimePicker1.Value+"','"+b+"','"+textBox6.Text+"','"+a+"','"+c+"', '"+textBox7.Text+"')";
SqlCommand cmd = new SqlCommand(uba, con);
SqlCommand X = new SqlCommand(A, con);
cmd.ExecuteNonQuery();
X.ExecuteNonQuery();
try
{
if (int.Parse(textBox9.Text) > int.Parse(textBox3.Text))
{
string B = "insert into BulkAvailable(ProductSource,ProductName,Date,Quantity,Type) values('" + textBox2.Text + "','" + textBox1.Text + "','" + dateTimePicker1.Text + "','" + d + "','" + textBox6.Text + "')";
SqlCommand Bc = new SqlCommand(B, con);
Bc.ExecuteNonQuery();
}
else
{
MessageBox.Show("You successfully Bought and Sold", " ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
catch (Exception aze)
{
MessageBox.Show(aze.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
MessageBox.Show("Operation Successfully Executed", " ", MessageBoxButtons.OK, MessageBoxIcon.Information);
con.Close();
}
catch (Exception er)
{
MessageBox.Show(er.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
When I run the code it returns an exception message: "String of binary data would be truncated. The statement has been terminated"