C# Database Insert (ASP.NET) - ExecuteNonQuery: CommandText property has not been initialized -
first time i'm doing insert asp.net/c# , i'm having little issue. keep getting following error every time code runs: " executenonquery: commandtext property has not been initialized" know means , how fix it?
thanks in advance!
string sqlquery = "insert ati_log_io (date, connect_time, disconnect_time, ati_rep, reason_for_access, property_contact, case_number, comments, property_id)"; sqlquery += "values (@today, @connect, @disconnect, @rep, @reason, @contact, @casenum, @comments, @propertyid)"; using (sqlconnection dataconnection = new sqlconnection(connectionstring)) { using (sqlcommand datacommand = dataconnection.createcommand()) { dataconnection.open(); datacommand.commandtype = commandtype.text; datacommand.commandtext = sqlquery; datacommand.parameters.add("@today", datetime.today.tostring()); datacommand.parameters.add("@connect", txtindate.text + " " + fromhrs.text + ":" + frommins.text + ":00"); datacommand.parameters.add("@disconnect", txtoutdate.text + " " + tohrs.text + ":" + frommins.text + ":00"); datacommand.parameters.add("@rep", repid); datacommand.parameters.add("@reason", txtreason.text); datacommand.parameters.add("@contact", txtcontact.text); datacommand.parameters.add("@casenum", txtcasenum.text); datacommand.parameters.add("@comments", txtcomments.text); datacommand.parameters.add("@propertyid", lstproperties.selectedvalue); datacommand.executenonquery(); dataconnection.close(); } }
string sqlquery = "insert ati_log_io (date, connect_time, disconnect_time, ati_rep, reason_for_access, property_contact, case_number, comments, property_id)"; sqlquery += " values (@today, @connect, @disconnect, @rep, @reason, @contact, @casenum, @comments, @propertyid)"; using (sqlconnection dataconnection = new sqlconnection(connectionstring)) { using (sqlcommand datacommand = new sqlcommand(sqlquery, dataconnection)) { datacommand.parameters.addwithvalue("today", datetime.today.tostring()); datacommand.parameters.addwithvalue("connect", txtindate.text + " " + fromhrs.text + ":" + frommins.text + ":00"); datacommand.parameters.addwithvalue("disconnect", txtoutdate.text + " " + tohrs.text + ":" + frommins.text + ":00"); datacommand.parameters.addwithvalue("rep", repid); datacommand.parameters.addwithvalue("reason", txtreason.text); datacommand.parameters.addwithvalue("contact", txtcontact.text); datacommand.parameters.addwithvalue("casenum", txtcasenum.text); datacommand.parameters.addwithvalue("comments", txtcomments.text); datacommand.parameters.addwithvalue("propertyid", lstproperties.selectedvalue); dataconnection.open(); datacommand.executenonquery(); dataconnection.close(); } }
copy-paste should trick
Comments
Post a Comment