窗口表单中的日期时间选择器语法错误 [英] Date time picker syntax error in window forms

查看:55
本文介绍了窗口表单中的日期时间选择器语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  private   void  button2_Click(对象发​​件人,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,txtdurationimprisonme nt.Text,txtdailydietmonety.Text,txtamountreceived.Text,dtpreceiptamount.Value.ToString(),txtprivateproperty.Text,txtbalanceleft.Text,txtbalancedisposedoff.Text);
MessageBox.Show( 数据已成功插入);


// 数据层中的代码

public void insertadmitcivilprison( string dateofadmission, string pmsno, string 囚犯名称, string prisonerfathername, string 性别,字符串职业, string village, string district, string height, string phesiogamy,字符串年龄,字符串住所, 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 持续时间_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到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_durat ion,daily_diet_allowance_granted,amount_received,date_of_recieve,property_recieved,balance_left,balance_disposed_off)values(' + dateofadmission + ',' + pmsno + ',' +囚犯名称+ ',' +囚犯姓名+ ',' + gender + ',' +占用+ ',' + village + ',' + district + ',' + height + ',' + phesiogamy + < span class =code-string> ',' + age + ',' + residence + ',' + caste + ',' + education + ',' + police_station + ',' + color + < span class =code-string>',' + 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 + '));



它给出以下错误



日期时间值不正确:'05 -Dec-13 10:33:36 AM'第1行

解决方案

您可以在传入数据库之前格式化DateTime值。你可以用这样的方法来格式化日期值。

  string  admissionDate = dtpadmission.Value.ToString (  yyyyMMdd); 





欲了解更多信息,请参阅此处,

http://msdn.microsoft.com/en-us/library/h2ef6zxz(v = vs.85).aspx [ ^ ]


如果date_of_admission是一个字符串,您通过日期时间选择器控件分配它,然后尝试更改这样的格式。



string date_of_admission = DtpAdmission.Value.ToString(yyyy- MM-DD);

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

解决方案

You can format the DateTime value before passing into the database. You can use something like this to format the date value.

string admissionDate = dtpadmission.Value.ToString("yyyyMMdd");



For more information refer here,
http://msdn.microsoft.com/en-us/library/h2ef6zxz(v=vs.85).aspx[^]


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");


这篇关于窗口表单中的日期时间选择器语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆