Click here to Skip to main content
15,914,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void button2_Click(object sender, EventArgs e)
       {
dLayer.insertadmitcivilprison(dtpadmission.Value.ToString(), txtpmsno.Text.ToString(), txtname.Text.ToString(), txtfname.Text.ToString(), cmbgender.SelectedItem.ToString(), txtoccupation.Text, txtvillage.Text, txtdistrict.Text, txtheight.Text, txtphesiogamy.Text, txtage.Text, cmbresidence.SelectedItem.ToString(), txtcaste.Text, txteducation.Text, txtpolicestation.Text, txtcolor.Text, txtidentification.Text, Txtwhichprison.Text, txtwhytransfered.Text, txtsrnoformerprison.Text, txtnamedetainingcreditor.Text, txtamountofclaim.Text, txtsentenceauthority.Text, txtcauseofdetention.Text, txtwarrantno.Text, dtpwarrantdate.Value.ToString(), dtpexpirydate.Value.ToString(),dtpreleasedate.Value.ToString(), txtweightondischarge.Text, txtweightonadmission.Text, txtrealeaseauthority.Text, txtdurationimprisonment.Text, txtdailydietmonety.Text, txtamountreceived.Text, dtpreceiptamount.Value.ToString(), txtprivateproperty.Text, txtbalanceleft.Text, txtbalancedisposedoff.Text);
MessageBox.Show("Data inserted Successfully");


//code in data layer

public void insertadmitcivilprison(string dateofadmission,string pmsno, string prisonername, string prisonerfathername, string gender, string occupation, string village, string district, string height, string phesiogamy, string age, string residence, string caste, string education, string police_station, string color, string identification_mark, string from_which_prison, string why_trasfered, string PMS_in_former_prison, string detaining_creditor, string amount_of_claim, string sentencing_authority, string cause_of_detention, string warrant_no, string warrant_date, string expiry_date_imprisonment, string release_date, string weight_on_discharge, string weight_on_admission, string authority_for_release, string duration_imprisonment, string diet_money, string amount_received, string date_receipt_amount, string private_property, string balance_left, string balance_disposedoff)

 CallingSystem.SqlHelper.ExecuteNonQuery(con, CommandType.Text, "insert into pcms.tbl_prisoner_detail (date_of_admission,pmsno,pname,pfname,sex,last_occupation,address,district,height,phesiogamy,age,residence,caste,education_qualification,police_station,color,identification_mark,previous_prison,transfer_reason,registration_no_pre_prison,detaining_creditor,amount_of_claim,sentencing_authority,reason_for_detention,warrant_no,date_of_warrant,expiry_date_imprisonment,date_of_release,weight_on_discharge,weight_on_admission,authority_of_discharge,imprisionment_duration,daily_diet_allowance_granted,amount_received,date_of_recieve,property_recieved,balance_left,balance_disposed_off) values('" + dateofadmission + "','" + pmsno + "','" + prisonername + "','" + prisonerfathername + "','" + gender + "','" + occupation + "','" + village + "','" + district + "','" + height + "','" + phesiogamy + "','" + age + "','" + residence + "','" + caste + "','" + education + "','" + police_station + "','" + color + "','" + identification_mark + "','" + from_which_prison + "','" + why_trasfered + "','" + PMS_in_former_prison + "','" + detaining_creditor + "','" + amount_of_claim + "','" + sentencing_authority + "','" + cause_of_detention + "','" + warrant_no + "','" + warrant_date + "','" + expiry_date_imprisonment + "','" + release_date + "','" + weight_on_discharge + "','" + weight_on_admission + "','" + authority_for_release + "','" + duration_imprisonment + "','" + diet_money + "','" + amount_received + "','" + date_receipt_amount + "','" + private_property + "','" + balance_left + "','" + balance_disposedoff + "')");

It gives following error

Incorrect datetime value: '05-Dec-13 10:33:36 AM' for column 'date_of_admission' at row 1
Posted
Updated 4-Dec-13 18:56pm
v2
Comments
Vishal Pand3y 5-Dec-13 0:59am    
your code is still not clear to me :(
Yadvinder Kumar 5-Dec-13 1:03am    
pls help me
Vishal Pand3y 5-Dec-13 1:16am    
see there might be some mistake while reading date_of_admission
Vishal Pand3y 5-Dec-13 1:12am    
in which line you are getting this errot msg
Yadvinder Kumar 5-Dec-13 1:14am    
in sql helper
int result = cmd.ExecuteNonQuery();

You can format the DateTime value before passing into the database. You can use something like this to format the date value.
C#
string admissionDate = dtpadmission.Value.ToString("yyyyMMdd");


For more information refer here,
http://msdn.microsoft.com/en-us/library/h2ef6zxz(v=vs.85).aspx[^]
 
Share this answer
 
IF date_of_admission is a string where you are assigning it by a datetime picker control,then try this to change the format like this.

string date_of_admission = DtpAdmission.Value.ToString("yyyy-MM-dd");
 
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