asp.net - String or binary data would be truncated. The statement has been terminated -
protected sub cmdok_click(byval sender object, byval e system.eventargs) handles cmdok.click dim medid, medname, comment string dim power, period, qtty integer 'dim nextdateofdelivery date = getnextdateofdelivery(val(txtdays.text)) dim today system.datetime dim answer system.datetime today = system.datetime.now answer = today.adddays(val(txtdays.text)) dim nextdateofdelivery date = answer medname = trim(txtmedname.text) qtty = val(txtquantity.text) comment = txtcomment.text power = txtpower.text medid = lblmedid.text period = val(txtdays.text) '............setting priorities '.......value of p(0) indicates priority tablest , on forth..... dim p() integer = {0, 0, 0, 0} = 0 lbpriorities.items.count - 1 select case lbpriorities.items(i).text case "tablet" p(0) = + 1 case "capsule" p(1) = + 1 case "liquid" p(2) = + 1 case "injection" p(3) = + 1 end select next '............if not available dim strictlythis string = radnotavailable.selecteditem.value dim connstr string = configurationmanager.connectionstrings("databaseconnectionstring").connectionstring dim con new sqlclient.sqlconnection(connstr) 'dim con new sqlclient.sqlconnection("data source=.\sqlexpress;" & _ ' "attachdbfilename=|datadirectory|\database.mdf;" & _ ' "integrated security=true;user instance=true") dim sql new sqlclient.sqlcommand("insert medicine" & _ "(medid, userid, medname, quantity, dateoforder, power, tabpriority, cappriority, liqpriority, " & _ "injpriority, period, notavailable, prescription, comment, nextdateofdelivery)" & _ "values('" & medid & "','" & user.identity.name & "','" & medname & "'," & qtty & ",'" & today & "'," & power & _ "," & p(0) & "," & p(1) & "," & p(2) & "," & p(3) & ",'" & period & "','" & strictlythis & "', '' ,'" & comment & "','" & nextdateofdelivery & "')", con) con.open() sql.executenonquery() con.close() con.dispose() lblmessage.text = "the details of medicine have been saved. may upload prescription" fuprescription.enabled = true cmdupload.enabled = true end sub this using now...but error saying "string or binary data truncated. statement has been terminated." mean???is there wrong sql statement???
i'd value you're storing in dateoforder.
according screenshot, varchar(10), you're storing datetime.now.tostring() in there, default value of of format:
5/1/2008 6:32:06 pm which comes in @ 19 characters.
i suggest store dates , times in more suitable field, such date or datetime field.
if must store text, should @ least store in format suitable sorting, , unambiguous, such as:
datetime.now.tostring("o") // round-trip format which give you:
2008-06-15t21:15:07.0000000
Comments
Post a Comment