really IMPOSSIBLE?
-
Hello Friends, I am really sorry for this stupid question. But I really have to solve this question: I want to execute an INSERT command via my save button on my webform. The procedure like below: ---------------------------------------------------------- string strSQL="INSERT INTO SupplierOperations VALUES (" + txtOrderNum.Text + ",'" + txtModelNum.Text + "','" + TextBox1.Text + "," + . . . . ----------------------------------------------------------- How can I convert TextBox.Text value to SMALLDATETIME I have tried Convert.ToDateTime(TextBox1.Text)....But did not work!! I also copied this code part and tried to run it on to Sql Server Query analyzer and did not work.. Please help...really urgent situation -- modified at 7:45 Thursday 11th May, 2006
-
Hello Friends, I am really sorry for this stupid question. But I really have to solve this question: I want to execute an INSERT command via my save button on my webform. The procedure like below: ---------------------------------------------------------- string strSQL="INSERT INTO SupplierOperations VALUES (" + txtOrderNum.Text + ",'" + txtModelNum.Text + "','" + TextBox1.Text + "," + . . . . ----------------------------------------------------------- How can I convert TextBox.Text value to SMALLDATETIME I have tried Convert.ToDateTime(TextBox1.Text)....But did not work!! I also copied this code part and tried to run it on to Sql Server Query analyzer and did not work.. Please help...really urgent situation -- modified at 7:45 Thursday 11th May, 2006
"Did not work" is not sufficient to help you solve the problem. Post the code used, the error message any any other relevant information. Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
-
"Did not work" is not sufficient to help you solve the problem. Post the code used, the error message any any other relevant information. Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
First of all,I would like to tell thank you very much for your attention... The problem is very clear I think.. INSERT INTO tbl1 VALUES (........) How can I convert the TextBox string to a SmallDateTime value?
-
First of all,I would like to tell thank you very much for your attention... The problem is very clear I think.. INSERT INTO tbl1 VALUES (........) How can I convert the TextBox string to a SmallDateTime value?
string strSQL="INSERT INTO SupplierOperations VALUES (" + txtOrderNum.Text + ",'" + txtModelNum.Text + "','" + ddListVendor.SelectedItem.Text + "','" + DropDownList3.SelectedItem.Text + "','" + txtModelType.Text + "','" + txtModelExp.Text + "','" + ddlistGrup.SelectedItem.Text + "'," + Convert.ToDateTime(Textbox2.Text) + "," + Convert.ToDateTime(TextBox1.Text) + "," +(TextBox6.Text) + "," + txtTerminDayCount.Text + "," + txtOKcount.Text + "," + txtConditionCount.Text + "," + txtStopCount.Text + "," + txtTotalCount.Text + "," + txtControlCount.Text + "," + txtMajor.Text + ")"; try { CollConnection.Open(); SqlCommand cmd=new SqlCommand(strSQL,CollConnection); cmd.ExecuteNonQuery(); . . Enough??
-
string strSQL="INSERT INTO SupplierOperations VALUES (" + txtOrderNum.Text + ",'" + txtModelNum.Text + "','" + ddListVendor.SelectedItem.Text + "','" + DropDownList3.SelectedItem.Text + "','" + txtModelType.Text + "','" + txtModelExp.Text + "','" + ddlistGrup.SelectedItem.Text + "'," + Convert.ToDateTime(Textbox2.Text) + "," + Convert.ToDateTime(TextBox1.Text) + "," +(TextBox6.Text) + "," + txtTerminDayCount.Text + "," + txtOKcount.Text + "," + txtConditionCount.Text + "," + txtStopCount.Text + "," + txtTotalCount.Text + "," + txtControlCount.Text + "," + txtMajor.Text + ")"; try { CollConnection.Open(); SqlCommand cmd=new SqlCommand(strSQL,CollConnection); cmd.ExecuteNonQuery(); . . Enough??
hi just try with this. DateTime tempTime = Convert.ToDateTime(DateTime.Now.Tostring()); textbox1.text=tempTime.ToShortDateString(); and call this textbox1 in sql statement Bhasker
-
hi just try with this. DateTime tempTime = Convert.ToDateTime(DateTime.Now.Tostring()); textbox1.text=tempTime.ToShortDateString(); and call this textbox1 in sql statement Bhasker
Thank you very much for your attenton...But Unfortunately the result is not correct... I really wonder is this really an IMPOSSIBLE question???
-
Hello Friends, I am really sorry for this stupid question. But I really have to solve this question: I want to execute an INSERT command via my save button on my webform. The procedure like below: ---------------------------------------------------------- string strSQL="INSERT INTO SupplierOperations VALUES (" + txtOrderNum.Text + ",'" + txtModelNum.Text + "','" + TextBox1.Text + "," + . . . . ----------------------------------------------------------- How can I convert TextBox.Text value to SMALLDATETIME I have tried Convert.ToDateTime(TextBox1.Text)....But did not work!! I also copied this code part and tried to run it on to Sql Server Query analyzer and did not work.. Please help...really urgent situation -- modified at 7:45 Thursday 11th May, 2006
You really need to be using parameters instead of concatenated strings. Not only is it faster, but it's safer. Since you only had 3 fields in your insert statement, that's all I put in this example
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Your_Connection_String_Here";
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = @"INSERT INTO [SupplierOperations ] VALUES (@orderNum, @modelNum, @other);"; // <-- paramaters here named whatever you want.SqlParameter p1 = new SqlParameter();
p1.SqlDbType = SqlDbType.NVarChar; // <-- didn't bother guessing the db type for this field or the next one
p1.ParameterName = "@orderNum";
p1.Value = txtOrderNum.Text;SqlParameter p2 = new SqlParameter();
p2.SqlDbType = SqlDbType.NVarChar;
p2.ParameterName = "@modelNum";
p2.Value = txtModelNum.Text;SqlParameter p3 = new SqlParameter();
p3.SqlDbType = SqlDbType.SmallDateTime; // <-- this is where ado.net automatically converts the value provided to smalldatetime.
p3.ParameterName = "@other";
p3.Value = TextBox1.Text;cmd.Parameters.AddRange(new SqlParameter[] { p1, p2, p3 });
cmd.ExecuteNonQuery();
Found on Bash.org [erno] hm. I've lost a machine.. literally _lost_. it responds to ping, it works completely, I just can't figure out where in my apartment it is.
-- modified at 13:11 Thursday 11th May, 2006