0

Greeting everyone, I come across a problem when trying to retrieve white space from SQLCE database. I'm using Visual Studio 2008, VB.NET, v3.5 Compact Framework, it's a Smart Device Project.

I have to store white space into database for text split later.

I retrieve the data from database using the below method :

    Dim da As New SqlCeDataAdapter("SELECT * FROM tblMaker WHERE maker_id = ?", openConn())
    da.SelectCommand.Parameters.AddWithValue("maker_id", cboMaker.SelectedValue)
    Dim ds As New DataSet
    da.Fill(ds)
    ds.Tables(0).Rows(0)(0) 'this method

For example, ds.Tables(0).Rows(0)(2) is a white space. But when I try to retrieve it, it return nothing instead giving me a white space.

The method I use to split text is : readerData.Text.Split("" & ds.Tables(0).Rows(0)(2) & "")(1)

So my question is how can I retrieve the white space from database? It seem that it consider a whitespace as NULL hence return me nothing.

My temporary solution is populate the data into a DataGrid and retrieve value from DataGrid directly, but this is not a good solution, please advice. :)

P/S : whitespace mean " "

Thanks!

Milo Khoo
  • 53
  • 2
  • 11
  • Why do you need a record in your database consisting just in " " at all? – varocarbas Sep 26 '13 at 17:39
  • @varocarbas As I mentioned I need it for split purpose later, there are a setting for user to set it. Eg. : a line of text [ABCDE 123A], the user want to take text after " ", so the user need to set " "~ – Milo Khoo Sep 26 '13 at 19:20
  • 1
    This is what I understood. But then why not using " " directly? why storing (and then retrieving) it in the DB. Why not replacing `readerData.Text.Split("" & ds.Tables(0).Rows(0)(2) & "")` with `readerData.Text.Split(" ")`? If you are considering different scenarios (accounting for blank spaces or not) you might store it via boolean variable: blank_spaces true/false. Or if you want to allow the user input different separation characters you might write "BLANK_SPACE" when the input is " ", this would solve your problem. Please, describe your exact conditions such that I can help. – varocarbas Sep 26 '13 at 19:22
  • @varocarbas Yup the user are allowed to input different separation characters, each setting are assigned for different , that's why I need to store it into DB and then retrieve it (like a setting). I'm taking your suggestion by changing "BLANK_SPACE" if input is " ", but the thing I concern is what if user key in 2 blank space? How do I make sure it always convert to "BLANK_SPACE" if user input a blank space? Thanks a lots! – Milo Khoo Sep 26 '13 at 19:44
  • 1
    You can track the blank spaces easily by doing: `if(inputString.Trim.Length = 0) then` -> the input consists in blank spaces for sure. `inputString.Length` would tell you the number of blank spaces. From that you can write as many BLANK_SPACE as required or BLANK_SPACE(no_of_blank_spaces) – varocarbas Sep 26 '13 at 19:48
  • 1
    Or... you might force the user to write the separation character(s) between symbols you can easily track, for example: single quotes. In this way, users might input 'sep_char ' -> blank space at the end. Also this kind of solution would solve the blank spaces issue. – varocarbas Sep 26 '13 at 19:53

0 Answers0