Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello sir/madam
I am trying to append some data in a column and using the given code...
C#
string query1 = "update arms_records set renewal_dates= 'hii' & renewal_dates where thana='Hkksik' and licence_number='6652'";

 string query2 = "update arms_records set renewal_dates='" + dateTimePickerRenewDate.Value.ToString() + "' & renewal_dates where thana='" + comboBoxthana.SelectedText +"' and licence_number='" + textBoxLicence_number.Text + "'";

while I use query1 it works and data is appended and saved.
but i want to use query 2. but nothing is saved in database.
Thank you ...
Posted
Comments
Sibasisjena 3-Jan-14 6:52am    
Please check the comboBoxthana.SelectedText and textBoxLicence_number.Text values are not null before use these. Else check record is there in db for the corresponding values.

If the record is not there, how it will be saved.
Member 10358986 4-Jan-14 0:36am    
Thank you very much
there was a small mistake in my syntax...
it should be combobxthana.Text instead of comboboxthana.SelectedText

SQL
tring query2 = "update arms_records set renewal_dates=" + dateTimePickerRenewDate.Value.ToString() + " & renewal_dates where thana=" + comboBoxthana.SelectedText +"and licence_number=" +textBoxLicence_number.Text ;
 
Share this answer
 
Comments
CHill60 3-Jan-14 11:56am    
This doesn't work when I try it
Don't use string concatenation when creating your query string. It leaves you open to sql injection attacks, creates extra work for you and makes your query unwieldy and difficult to debug.

Use Parameters instead - http://www.dotnetperls.com/sqlparameter[^]

Then do as Sibasis05 has suggested - debug your code and check that comboBoxthana.SelectedText and textBoxLicence_number.Text actually contain some data. Also check that the data actually matches to a record in your table - watch out for spelling mistakes and capitalisation
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900