hi developing own project in asp.net mvc5 getting error when using insert command , writing query in 'string.format' , error 'an exception of type 'system.data.sqlclient.sqlexception' occurred in system.data.dll not handled in user code
additional information: conversion of varchar data type datetime data type resulted in out-of-range value.
the statement has been terminated.'
and code is
`public void addcar(car obj)
{ string strconn = "server = amarnath\\server; database = carparking; integrated security = true;"; string cmdtext = string.format("insert car(parking_id, car_no, mobile_no, starting_time, ending_time, total_time, charges) values({0}, '{1}', {2}, '{3}', '{4}', '{5}', '{6}');" + "select @@identity", obj.parking_id, obj.car_no, obj.mobile_no, obj.starting_time.tostring(), obj.ending_time.tostring(), obj.total_time, obj.charges); sqlconnection conn = new sqlconnection(strconn); sqlcommand cmd = new sqlcommand(cmdtext, conn); conn.open(); cmd.executenonquery(); conn.close(); }`
and want know best way write query in string.format or parameterised
Comments
Post a Comment