Sunday, 15 August 2010

vb.net - Conversion of Varchar to int -



vb.net - Conversion of Varchar to int -

need help! cannot retrieve info in sq l, because value 100-200 , says needs converted integer, var char info type. think problem "-", error in code in info table code, do?

private sub retrivedata(byval id string) if sql.hasconnection() = true dim dt datatable = sql.executedatatable("select (empid varchar), firstname,midname,lastname,gender,birthdate,civilstat,address,contactnum employeetable empid=" & id) each info datarow in dt.rows empid_txt.text = data(0) firstname_txt.text = data(1) middlename_txt.text = data(2) lastname_txt.text = data(3) gender_cb.text = data(4) birthdate_dtp.value = data(5) civilstat_cb.text = data(6) address_txt.text = data(7) contact_txt.text = data(8) next else msgbox("system database cannot connected", msgboxstyle.information) end if end sub

actually, assuming 100-200 values in table somewhere, error in cranium of developer decided utilize varchar store numeric value :-)

either that, or developer decided take otherwise free-form text field , assume going single numeric value.

as how prepare it, 1 of paragraphs needs worked around. if want single numeric value in table, should alter numeric type field, along way going through 100-200 style values , cleaning them (into, example, 150).

if want able store ranges, code processes them going have more intelligent, such extracting lower , upper value column , running loop process values within range, or changing query (pseudo-codish query):

where empid = ?value?

into:

where empid >= ?low? , empid <= ?high?

we can't tell which best solution based on info provided, business decision rather technical one.

if assumption wrong , it's id argument (being used in where clause) function retrivedata (sic), either need stop users entering that, or create code processes argument more intelligent (similar looping/changed-query suggestion above).

vb.net sql-server-2008

No comments:

Post a Comment