Question

  command.CommandType = CommandType.StoredProcedure
            command.CommandText = "{?=call gtab09_INSERT(_acyrid,_RepId,_DrId,_vrid,_mode, _trno, _trdate, _acid, _vrno, _SuppId,_custname,_netamt,_disrate,_disamt,_RoundOff,_jrmid, _userid,_userdtm,_VSNo,_RecdAmt,_cstrate,_cstsaleamt,_cstamt,_tdrate,_tdamt,_cdrate,_cdamt,_CessRate,_CessAmt,_odesc1,_oamt1,_CashCredit,_OrderNo,_OrderDate,_CustAdd2,_Remarks,_WhoRetSl,_PatName,_DrName,_FormId,_SalesMan,_CFMode,_PatId,_StkPtId,_DisType,_BranchID)}"
            command.Parameters.Add("_acyrid", gintAcYrId)
            command.Parameters.Add("_RepId", Val(cboRep.SelectedValue))
            command.Parameters.Add("_DrId", Val(cboDoctor.SelectedValue))
            command.Parameters.Add("_vrid", mlngVrId)
            command.Parameters.Add("_mode", Val(cboMode.SelectedIndex))
            command.Parameters.Add("_trno", txtslno.Text)
            command.Parameters.Add("_trdate", Format(dteDate, "yyyy-MM-dd"))
            command.Parameters.Add("_acid", CustAcId)

I am getting

Unable to cast object of type 
'C1.Win.C1Input.C1DateEdit' to type 'System.IConvertible' error

in

command.Parameters.Add("_trdate", Format(dteDate, "yyyy-MM-dd"))

using VB.net 2008 and PostgreSql Database in postgres date field should be in yyyy-MM-dd Format. This is an Insert function

Was it helpful?

Solution

Your current code is trying to convert C1DateEdit control to a formatted string which is not valid operation. I guess you want to convert DateTime value from that control instead :

command.Parameters.Add("_trdate", Format(dteDate.Value, "yyyy-MM-dd"))

assuming that dteDate.Value is a correct way to get DateTime value from C1DateEdit, since I've never used ComponentOne control in my life. Anyway, if _trdate parameter expect a DateTime type in postgres, you can just pass a DateTime object as parameter value. No need to take care of formatting, it will be handled automatically. Something like this (same assumption applied) :

command.Parameters.Add("_trdate", dteDate.Value)

Hope this shed some lights to your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top