ask messagebox with sum record
-
how to create messagebox if save record success with sum record exemple string save=string.format("insert into quantity([input])values('{0}')",texbox1.tex); sqlconection con new sqlconection(); con.open(); sqlcommend cmd = new sqlcommend(); cmd.excutenonQuery(); con.close(); i want to show message=> messagebox.show"(Rcord 10 Item ");
-
how to create messagebox if save record success with sum record exemple string save=string.format("insert into quantity([input])values('{0}')",texbox1.tex); sqlconection con new sqlconection(); con.open(); sqlcommend cmd = new sqlcommend(); cmd.excutenonQuery(); con.close(); i want to show message=> messagebox.show"(Rcord 10 Item ");
1 Your insert query is wrong 2 You are using unverified data directly from your user - look up Little Bobby tables 3 You have no output from sql to get the information Personally I would build a parameterised stored procedure that insert/updates the record and returns the sum you are looking for. the result to be returned as either a single integer value using ExecuteScalar or as a table.
Never underestimate the power of human stupidity RAH
-
1 Your insert query is wrong 2 You are using unverified data directly from your user - look up Little Bobby tables 3 You have no output from sql to get the information Personally I would build a parameterised stored procedure that insert/updates the record and returns the sum you are looking for. the result to be returned as either a single integer value using ExecuteScalar or as a table.
Never underestimate the power of human stupidity RAH
i want to show messagebox sum row/record with messagebox private void bsave_Click(object sender, EventArgs e) { string save = string.Format("Insert into ShippingCompany([ShippingCompanyCode],[ShippingCompanyName],[CurenccyCode],[ActiveStatus],[CreateBy],[CreateDate],[modifiedBy],[modifiedDate])values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", t1.Text, t2.Text, t3.Text, t4.Text, t5.Text, DateTime.Now.ToString("yyyy-mm-DD" + "HH:mm:ss"), t7.Text, DateTime.Now.ToString("yyyy-mm-DD" + "HH:mm:ss")); SqlConnection con = new SqlConnection(dikonek); con.Open(); SqlCommand cmd = new SqlCommand(save, con); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("?");
-
i want to show messagebox sum row/record with messagebox private void bsave_Click(object sender, EventArgs e) { string save = string.Format("Insert into ShippingCompany([ShippingCompanyCode],[ShippingCompanyName],[CurenccyCode],[ActiveStatus],[CreateBy],[CreateDate],[modifiedBy],[modifiedDate])values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", t1.Text, t2.Text, t3.Text, t4.Text, t5.Text, DateTime.Now.ToString("yyyy-mm-DD" + "HH:mm:ss"), t7.Text, DateTime.Now.ToString("yyyy-mm-DD" + "HH:mm:ss")); SqlConnection con = new SqlConnection(dikonek); con.Open(); SqlCommand cmd = new SqlCommand(save, con); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("?");
You did not understand my last answer, you obviously have no idea how to do database operations and you are making the most basic error by storing dates as text. PLEASE get a book, work through the examples and then do some tutorials on the subject, you do not even have enough knowledge yet to as sensible questions.
Never underestimate the power of human stupidity RAH
-
i want to show messagebox sum row/record with messagebox private void bsave_Click(object sender, EventArgs e) { string save = string.Format("Insert into ShippingCompany([ShippingCompanyCode],[ShippingCompanyName],[CurenccyCode],[ActiveStatus],[CreateBy],[CreateDate],[modifiedBy],[modifiedDate])values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", t1.Text, t2.Text, t3.Text, t4.Text, t5.Text, DateTime.Now.ToString("yyyy-mm-DD" + "HH:mm:ss"), t7.Text, DateTime.Now.ToString("yyyy-mm-DD" + "HH:mm:ss")); SqlConnection con = new SqlConnection(dikonek); con.Open(); SqlCommand cmd = new SqlCommand(save, con); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("?");
What Mycroft has stated is correct you shouldn't store dates in the database as strings but I wont go into that as he already has. If you look at the ExecuteNonQuery[^] documentation you will see that the method returns a value indicating the number of rows effected. you can then use this value in a string.
string Message = String.Format("Number of rows affected {0}", result);
MessageBox.Show(Message);Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON
-
i want to show messagebox sum row/record with messagebox private void bsave_Click(object sender, EventArgs e) { string save = string.Format("Insert into ShippingCompany([ShippingCompanyCode],[ShippingCompanyName],[CurenccyCode],[ActiveStatus],[CreateBy],[CreateDate],[modifiedBy],[modifiedDate])values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", t1.Text, t2.Text, t3.Text, t4.Text, t5.Text, DateTime.Now.ToString("yyyy-mm-DD" + "HH:mm:ss"), t7.Text, DateTime.Now.ToString("yyyy-mm-DD" + "HH:mm:ss")); SqlConnection con = new SqlConnection(dikonek); con.Open(); SqlCommand cmd = new SqlCommand(save, con); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("?");
Avoiding SQL Injection[^] isn't hard:
string save = "Insert into ShippingCompany ([ShippingCompanyCode], [ShippingCompanyName], [CurenccyCode], [ActiveStatus], [CreateBy], [CreateDate], [modifiedBy], [modifiedDate]) "
+ "values (@ShippingCompanyCode, @ShippingCompanyName, @CurenccyCode, @ActiveStatus, @CreateBy, @CreateDate, @modifiedBy, @modifiedDate)";using (SqlConnection con = new SqlConnection(dikonek))
using (SqlCommand cmd = new SqlCommand(save, con))
{
cmd.Parameters.AddWithValue("@ShippingCompanyCode", t1.Text);
cmd.Parameters.AddWithValue("@ShippingCompanyName", t2.Text);
cmd.Parameters.AddWithValue("@CurenccyCode", t3.Text);
cmd.Parameters.AddWithValue("@ActiveStatus", t4.Text);
cmd.Parameters.AddWithValue("@CreateBy", t5.Text);
cmd.Parameters.AddWithValue("@CreateDate", DateTime.Now);
cmd.Parameters.AddWithValue("@modifiedBy", t7.Text);
cmd.Parameters.AddWithValue("@modifiedDate", DateTime.Now);con.Open();
int rowsAffected = cmd.ExecuteNonQuery();
MessageBox.Show(string.Format("{0} rows affected.", rowsAffected));
}You should also consider giving your controls more meaningful names than
t1
,t2
, etc.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer