|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
CHANGING DATA TYPEDim ProductPropertyValues_Value as string
ProductPropertyValues_Value = xx("ProductPropertyValues_Value") it returns error.. Because xx("ProductPropertyValues_Value") returns NULL or "" records? How can i convert it to string or which method should i use it ? "Savas Ates" <in da club> schrieb Did you enable Option Strict?> Dim ProductPropertyValues_Value as string > > > > ProductPropertyValues_Value = xx("ProductPropertyValues_Value") > > it returns error.. Because xx("ProductPropertyValues_Value") > returns NULL or "" records? > > How can i convert it to string or which method should i use it ? What is xx("ProductPropertyValues_Value")? What is the type of xx("ProductPropertyValues_Value")? What is the instance type of the object returned by xx("ProductPropertyValues_Value")? Armin Dim xx As SqlClient.SqlDataReader
I take values from my db by appliying that method. ? "Armin Zingler" <az.nospam@freenet.de>, haber iletisinde þunlarý yazdý:e%23YBbYcHGHA.2***@TK2MSFTNGP15.phx.gbl...Show quoteHide quote > "Savas Ates" <in da club> schrieb >> Dim ProductPropertyValues_Value as string >> >> >> >> ProductPropertyValues_Value = xx("ProductPropertyValues_Value") >> >> it returns error.. Because xx("ProductPropertyValues_Value") >> returns NULL or "" records? >> >> How can i convert it to string or which method should i use it ? > > > Did you enable Option Strict? > > What is xx("ProductPropertyValues_Value")? > > What is the type of xx("ProductPropertyValues_Value")? > > What is the instance type of the object returned by > xx("ProductPropertyValues_Value")? > > > Armin > "Savas Ates" <in da club> schrieb How do you intend to handle Null values coming from the database? You can> Dim xx As SqlClient.SqlDataReader > > I take values from my db by appliying that method. ? not store them in a string. Declare the variable As Object. dim ProductPropertyValues_Value as object ProductPropertyValues = xx("ProductPropertyValues_Value") Later, if you want to distinguish between Null and String, you have to write: if ProductPropertyValues_Value is dbnull.value then 'handle null value else 'handle string end if - OR - Some people convert DBNull to Nothing in order to be able to declare the variable As String: Dim ProductPropertyValues_Value as string dim o as object o = xx("ProductPropertyValues_Value") if o is dbnull.value then ProductPropertyValues_Value = Nothing else ProductPropertyValues_Value = o.ToString end if Later usage: if ProductPropertyValues_Value is nothing then '... else '... end if Later, if you want to save the values back to the database, you have to convert back from Nothing to DBNull.Value. Typed datasets, or classes that you create on your own, can have typed members (As String) that simplifies this (because the member is typed), and they have additional "IsMemberNull" and "SetMemberNull" methods. Armin Armin,
Do I see something wrong ToString or Cstr does mostly everything in these cases. However because all these answers I become confused. Cor "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb DBNull.Tostring probably gives not the result expected.> Armin, > > Do I see something wrong > > ToString or Cstr does mostly everything in these cases. > > However because all these answers I become confused. > > Cor Armin "Savas Ates" <in da club> schrieb: \\\> Dim ProductPropertyValues_Value as string > > ProductPropertyValues_Value = xx("ProductPropertyValues_Value") > > it returns error.. Because xx("ProductPropertyValues_Value") returns NULL > or "" records? > > How can i convert it to string or which method should i use it ? Dim Value As Object = xx("...") ' 'If Value Is DBNull.Value Then...'. If IsDBNull(Value) Then s = "" Else s = DirectCast(Value, String) End If /// -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schrieb This means, you can not distinguish between Null and "" anymore, later. I > Dim Value As Object = xx("...") > > ' 'If Value Is DBNull.Value Then...'. > If IsDBNull(Value) Then > s = "" guess this is not intended because if both were equal, the database design would be wrong (usually). Armin "Armin Zingler" <az.nospam@freenet.de> schrieb: This depends on what you want to archive. If the intention is to display >> Dim Value As Object = xx("...") >> >> ' 'If Value Is DBNull.Value Then...'. >> If IsDBNull(Value) Then >> s = "" > > This means, you can not distinguish between Null and "" anymore, later. I > guess this is not intended because if both were equal, the database design > would be wrong (usually). the values in labels or similar, then my code makes sense, IMO. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
Show quote
Hide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schrieb As from the OP's post I only see a String typed variable, I can not assume > "Armin Zingler" <az.nospam@freenet.de> schrieb: > > > Dim Value As Object = xx("...") > > > > > > ' 'If Value Is DBNull.Value Then...'. > > > If IsDBNull(Value) Then > > > s = "" > > > > This means, you can not distinguish between Null and "" anymore, > > later. I guess this is not intended because if both were equal, > > the database design would be wrong (usually). > > This depends on what you want to archive. If the intention is to > display the values in labels or similar, then my code makes sense, > IMO. that a label will be used. I can only answer based on the information I have. That's why I also assume the correct database design. Consequently, it does not make sense to convert Null to "". But let's wait for the OP's answer. Armin
Changed Date on PC, now project doesn't compile source code changes
Get information about Dial Up connections? Compressing (zipping) files dispose the login form vb.net tabpage copying dynamic Save lines drawn in the picturebox as an lmage Job LastRunOutCome?? search within a arraylist Parsing a string - please help Maximized MDI childforms.... Anyone? |
|||||||||||||||||||||||