คำตอบ Search ListView

  • 9 พฤษภาคม 2555 21:26
     
     

    Can anyone help me with this?

    How do I fix this code to highlight (in different color) and visible in the listview as user type in textbox.  It will display messages of not found if the item is not in listview and case is not sensitive

    Private Sub Textbox1.Textchanged(byval sender as system.object, byval e as system.eventargs) handles textbox1.textchagned

     For i = 0 To ListView1.Items.Count - 1    
    If ListView1.Items(i).SubItems(3).Text = TextBox1.Text Then         
    ListView1.Items(i).Selected = True  
    End If
    Next

     End Sub

    Thanks.

    Bob

    VS2008

     

ตอบทั้งหมด

  • 9 พฤษภาคม 2555 22:03
     
     

    Bob,

    See if this might give you some ideas?

    I have the code on a web page of my site (I hate this new code formatter they're using) and you can see it by clicking here. I only have three lines of data in it so of course it's fast, but if yours has a lot more, you may want to use the .Leave event rather than .TextChanged event.

    At any rate, the results are shown thusly:

    I hope it helps. :)

    Please call me Frank :)


  • 9 พฤษภาคม 2555 22:54
     
     

    Is the problem that you need to detect when there is no match?  Note that the user will probably not be pleased by messages occurring every keystroke indicating a failure to match.

    Dim Found as Boolean = False
    For i = 0 To ListView1.Items.Count - 1    
        If ListView1.Items(i).SubItems(3).Text = TextBox1.Text Then        
            ListView1.Items(i).Selected = True  
            Found = True
        End If 
    Next
    If Not Found Then
        'inform the user
    End If


  • 10 พฤษภาคม 2555 13:57
     
     

    Hi Frank,

    Thanks for helping me.  I tried your code and it did not do anything. I also tried .Leave Event and it did not anything either.  It seems very straightforward but for some reason, it does not work.  My records have about 3,000 (give or take).  Could it be two many records?

    Hi Acamar,

    I also tried your code and it did not work.  I need it to find a match (case not sensitive), if there is a match, I want it to hightlight it and visible on the listview. if there is no match, it would display a message of no match.

    Again, Thank you all for your help.

    Bob.



    • แก้ไขโดย LA_Bob 10 พฤษภาคม 2555 14:17
    •  
  • 10 พฤษภาคม 2555 14:20
     
     

    Bob,

    That's a lot for a listview!

    I don't know if that's an issue or not but one thing with yours that you'll want to do is to "EnsureVisible":

    http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.ensurevisible.aspx

    With my example it wasn't needed but with yours it surely is.

    I have another idea which might make things go faster, but try that first and let me know?


    Please call me Frank :)

  • 10 พฤษภาคม 2555 14:39
     
     

    Hi Frank,

    I tried EnsureVisible as you suggested and it did not do anything still. 

    Thanks,

    Bob

  • 10 พฤษภาคม 2555 14:42
     
     

    Hi Frank,

    I tried EnsureVisible as you suggested and it did not do anything still. 

    Thanks,

    Bob

    Odd,

    Before getting to the other idea, we need to establish why it's not working. How about put a breakpoint in and see if it ever finds it in the loop?


    Also make sure that you're using the correct subitem.

  • 10 พฤษภาคม 2555 15:15
     
     

    Hi Frank,

    I did double checked to make sure that the subitem is correct and it was correct.  I used the debugging window and It never finds it in the loop.

    Thanks,

    Bob

  • 10 พฤษภาคม 2555 15:31
     
     

    Hi Frank,

    I did double checked to make sure that the subitem is correct and it was correct.  I used the debugging window and It never finds it in the loop.

    Thanks,

    Bob


    Dang - I don't know, I'm stumped as to why it's not finding it.

    Please call me Frank :)

  • 10 พฤษภาคม 2555 15:52
     
     

    Bob,

    I'll explain my other idea, but it was really more a matter of speeding things up, so it doesn't answer the conundrum of why the code isn't finding it in the listview.

    My other idea though, was this: You're only searching for some particular column (subitem), and given that, my thought was to create a class. The class would only have two fields - the index (row number, zero-based) and the text of that column in that row. Next, create a list of that class and with that, you can use LINQ to find it pretty quickly.

    With it found, now use the index to show the highlighting. The only thing it leaves out is turning off the highlighting of any other rows, but that could be dealt with.

    Again though - none of that answers why the "find" isn't working presently.


    Please call me Frank :)

  • 10 พฤษภาคม 2555 16:13
     
     

    I find this interesting and thought I'd pass it along.

    It occurred to me that maybe (even though it makes no sense) the number of rows was the issue, so I modified my example code to look through a folder where there's some 17,000+ .mp3 sound files. I then split the path up and used those elements as the listview item/subitems:

    It found it as shown above, so even though a large number of items might not be desirable, I don't think that's the issue. Please check through the code again and set up something to let you know what subitem text is where. It could be something as simple as that (the first subitem is subitem1, not 0).

    Please call me Frank :)

  • 10 พฤษภาคม 2555 17:29
     
     

    Hi Frank,

    I checked the subitem and it was correct. I also tried different subitem as well, it did not work still.   Is there any other ways that you can make this to work?

    Thanks,

    Bob

  • 10 พฤษภาคม 2555 17:33
     
     

    Hi Frank,

    I checked the subitem and it was correct. I also tried different subitem as well, it did not work still.   Is there any other ways that you can make this to work?

    Thanks,

    Bob

    Well I can put together my idea using LINQ - in fact it wouldn't take that long, but I swear there's something we're missing here, and I'm betting it's something simple.

    Do you have a way to zip the project folder up, upload it somewhere, and let me try it?


    Please call me Frank :)

  • 10 พฤษภาคม 2555 18:06
     
     

    Bob,

    If you're interested in the other approach that I was talking about, have a look at the code here. I still think it's a mystery as to why the existing code isn't working though.


    Please call me Frank :)

  • 10 พฤษภาคม 2555 19:03
     
     

    Hi Frank,

    This is a challenge, how do I tie my database to that?

    What is your email address?

    Thanks,

    Bob




    • แก้ไขโดย LA_Bob 10 พฤษภาคม 2555 19:11
    •  
  • 10 พฤษภาคม 2555 19:16
     
     

    Hi Frank,

    This is a challenge, how do I tie my database to that?

    What is your email address?

    Thanks,

    Bob




    I don't give out my e-mail address but I can set up an FTP upload/download area and post the details here. Do you an FTP client?

    I'm not sure about the database part, I can try. What sort of database is it?


    Please call me Frank :)

  • 10 พฤษภาคม 2555 19:30
     
     

    Frank,

    No. I do not have FTP client.

    It is MS access database.

    I use OleDb to tie my database to the project.

    Thanks,

    Bob.

  • 10 พฤษภาคม 2555 19:45
     
     

    Let's try this. You can use your browser but I just prefer an actual client (and there are free ones if you're interested).

    I just created this so it's untested but it should work.


    Go to ftp://ftp.fls-tech.com/

    Login: vbforum

    Password: L5Mgq9S35$;f


    Let me know when you have it uploaded please?


    Please call me Frank :)

  • 10 พฤษภาคม 2555 20:37
     
     

    Hi Frank,

    it says cannot display webpage ............... went down?

    Thanks,

    Bob

  • 10 พฤษภาคม 2555 20:40
     
     

    Hi Frank,

    it says cannot display webpage ............... went down?

    Thanks,

    Bob

    No, I just tried it using that same link from in here.

    I'm not sure what the deal is. If you can't get it to work, or maybe this is the better idea anyway, post the relevant code here.


    Please call me Frank :)

  • 10 พฤษภาคม 2555 21:23
     
     

    Hi Frank,

    I will try it from home and see what happens.  I just cannot get it to work here.  I will let you know if I can do it from home or not.

    Thanks,

    Bob


    • แก้ไขโดย LA_Bob 10 พฤษภาคม 2555 21:24
    •  
  • 10 พฤษภาคม 2555 21:31
     
     

    Hi Frank,

    I will try it from home and see what happens.  I just cannot get it to work here.  I will let you know if I can do it from home or not.

    Thanks,

    Bob


    Sure, just let me know.

    By the way, you may or may not be aware, but all of your VB code for a particular form is all in a text file. Form1.vb, for instance, is just a plain simple ASCII text file. Not that I have a point here, but if we can't get things to connect, the information might come in handy. :)


    Please call me Frank :)

  • 10 พฤษภาคม 2555 21:32
     
     

    What do you mean 'did not work'?    Your original post contained three tasks - search the listview; take some action if a match is found; take some action if a match is not found.   The change I made to your code was only in respect of displaying a message when a match is not found, becasue that task was not addressed in your caode.

    What was the action you included for the case when a match was not found?   Did that action occur when the match was not found?

    Or is the problem that the code is not finding a match when it should, or that the highlighting is not occurring?

  • 10 พฤษภาคม 2555 22:48
     
     

    Hi Frank,

    I was able to upload the file to ftp site.  Please let me know if you see it on the web site at your end. Thank you.

    Hi Acamar,

    It did not find any match or highlight anything. it went straight to "not found".  Thank you for your help.

    It was not straightforward as I thought..........

    Thanks,

    Bob


    • แก้ไขโดย LA_Bob 10 พฤษภาคม 2555 22:50
    •  
  • 10 พฤษภาคม 2555 23:16
     
     

    What was the contents of the textbox?    What was the listview item that you expected it to match with?

  • 10 พฤษภาคม 2555 23:17
     
     

    Bob,

    I'm even more puzzled! Have a look at this:

    As you can see, in that test above, the "test" found it, but in the code just beneath it - which is functionally the very same thing - no, you're right, it wouldn't find it.

    I'm ... I dunno!

    Acamar?

    If anyone wants the code (and if Bob is ok with it), I can make an HTTP link where you can get it.

    Dang, this is a curious one for sure!


    Please call me Frank :)

  • 10 พฤษภาคม 2555 23:45
     
     

    What was the contents of the textbox?    What was the listview item that you expected it to match with?


    Acamar, was that directed to me? I don't read these like everyone does - I can't tell what's a follow-up unless someone tells me so.

    Please call me Frank :)

  • 11 พฤษภาคม 2555 0:00
     
     

    Hi Frank,

    You did not believe it until you ran the program ....... :)  Why didn't it work?

    Hi Hi Acamar,

    Below is the screenshot of it.   I would like to search company name, contact name or contact title and case is not sensitive.  Thank you for your help.  Bob


    • แก้ไขโดย LA_Bob 11 พฤษภาคม 2555 0:02
    •  
  • 11 พฤษภาคม 2555 0:04
     
     

    Hi Frank,

    You did not believe it until you ran the program ....... :)  Why didn't it work?

    No, honestly I didn't but I'm stumped on it.

    Oh I guess we could use that to trigger it, but that's not fixing it. We need to figure out why it's not working and for that ... goodness knows. I'm hoping Acamar or someone else might shine a light on it to let us both know!


    Please call me Frank :)

  • 11 พฤษภาคม 2555 0:08
     
     
    By the way, once we solve this conundrum, let's get away from what you're doing and move to much better ways involved a DataGridView and some LINQ (or fill queries) to do a lot more with less hassle. ;-)

    Please call me Frank :)

  • 11 พฤษภาคม 2555 1:11
     
     

    Hi Frank,

    Me Too, I hope someone out there that can help with this.  Thank you for trying though.

    Thanks,

    Bob

  • 11 พฤษภาคม 2555 1:48
     
      มีโค้ด

    Unfortunately, I cannot reproduce your problem. 

            For Each lv As ListViewItem In ListView1.Items
                If TextBox1.Text = lv.SubItems(2).Text Then
                    Stop
                End If
            Next

    That suggests to me that the problem is part of your data, not your code. You should insert a counter in that loop, count the sequence number of the item that you expect to match, and stop the loop when the counter hits that value.  Then examine the two data items character by character and, if necessary, byte by byte.  You may need to write some supporting data visualisation routines to see the two strings in the way that's needed to detect the diffrence, such as a little routine that outputs the values as a sequence of hex.

    Where has this data come from?  Can you view it in its original source using a hex viewer?  if you can, is there anything odd about that data that might cause a mismatch?

    Do you have an alternate version of this data?  For instance, if it's coming from a data base do you have a set of test data that may have been created differently, or can you create some data manually?  If so, test it on that alternate source and see if the problem persists.  Also test it with different sizes of data sets, and test it for matches that should occur in different parts of the list.

  • 11 พฤษภาคม 2555 15:20
     
     

    Hi Frank,

    I have a question for you.  Are you good with DataGridView and LINQ?

     

    Thanks,

    Bob

  • 11 พฤษภาคม 2555 16:07
     
     

    Hi Frank,

    I have a question for you.  Are you good with DataGridView and LINQ?

    Thanks,

    Bob

    Well ... define "good"! ;-)

    I'm ok with them but honestly I've not used the "out of the box" stuff in a long time. I prefer to use this one:

    http://www.devexpress.com/Products/NET/Controls/WinForms/Grid/

    But I can manage them ok I suppose.


    Please call me Frank :)

  • 13 พฤษภาคม 2555 21:13
     
     คำตอบ

    Bob,

    I still don’t know why the ListView won’t find what it should.

    Might it be the data itself as Acamar suggested? Well maybe, I honestly don’t know. I have uncovered some things regarding the data which I’ll eventually get to in this writing, but in my mind, I still don’t really think that’s the issue.

    The reason that I say that is because in last week’s test, I essentially asked VB “is A equal to B?” and it replied back “no”. I then asked “is B equal to A?” and it replied back “yes”.

    Huh??

    So I’m stuck on thinking that I just plain don’t know what the heck is wrong, but there are some anomalies in the data and that might be the problem as Acamar said in his last reply.

    Either way though, that’s not the purpose for what I’ll present here. I said the other night “let’s move to a different way” and what I’ll show is my idea of that different way.

    My Proposed Better Way

    The way that I have in mind is based on using a DataGridView rather than a ListView. This isn’t at all uncommon to show data from a dataset and is the basis of all this. Like I said the other day though, for my own programs, I’ll use Dev’s products; they’re just better and more feature-rich all around, but since you don’t have access to it, I’ll stick with the out-of-the-box DGV.

    Before getting into all the details, let me first give you a short guided tour. This is what the program looks like when first turned on (with your sample data already in place):

    At the top, I have a way that the user can find or filter the data, beneath the grid is a way that they can edit the data, and the buttons on the bottom are the means by which they’ll add a new customer, remove an existing customer, and update (save) the changes they make if they edit the data.

    I’ll get into the nuts and bolts of that in subsequent sections.

    Adding A New Customer

    The way that I do this is via another form shown modally:

    In that form, there are certain minimum required fields and everything is validated prior to allowing the new customer to be added. Once it has been validated, the new customer is added and the information is automatically updated (saved).

    Deleting A Customer

    If the user decides to remove a customer from the database, they’re asked first to confirm it:

    If they confirm that they want to delete the customer, then that customer is removed from the database and it’s automatically saved.

    Modifying The Data

    If the user modifies the data, the program recognizes this:

    As you can see above, the “Save Data” button is now enabled, and the form’s text (title bar) shows an asterisk appended to it. If they go to close the program but they haven’t yet saved their changes, they’ll see this:

    Shown above, they can exit the program without saving, they can exit the program but have the program save the changes first, or they can simply press the “Cancel” button and resume the program.

    Finding Data

    The ability to be able to quickly locate something in a sea of data is invaluable. In my mind, a “find” should only be used for instances where there’s only one match; ergo, unique (distinct) data. In this one, only one absolutely applies (Customer ID) and one probably applies (Contact Name), so that’s what I used.

    You can modify this to your liking of course, and using the methods that I’ll show in the code, it will still work and will simply locate the first row containing it.

    To do this, I have two ComboBoxes. The first allows them to choose either the Customer ID or the Contact Name:

    When they select one, the items in the second ComboBox are then populated and sorted alphabetically. It also has the AutoComplete set for it, so just typing in the ComboBox will quickly locate all applicable items:

    Once they make their selection, the program navigates to that row:

    If they choose the Contact Name, it works identically:

    Filtering The Data

    A fairly powerful feature built in to this is the ability to filter the data, and it’s not restricted to only show one of a particular type as shown below (this is also in another form, shown modally):

    I have this set to being able to filter the data based on one of following criteria:

    - Company Name

    - Location

    - Postal Code

    - Contact Title

    These are shown next:

    Unlike finding data, a filter actually creates a new dataset and ONLY shows what it’s been set to show:

    Once filtered, the “Show All Data” button is enabled, thus allowing the user to once again see all rows:

    In all of this, my hope is that it will give you some ideas on how you can either take mine and modify it for your use, or just use the ideas and methods to create a new one for your users. I’ll explain all of it in the next several threads.

    In my opinion, this is head and shoulders above using a ListView and I hope you’ll agree. :)


    Please call me Frank :)

    • ทำเครื่องหมายเป็นคำตอบโดย LA_Bob 14 พฤษภาคม 2555 20:59
    •  
  • 13 พฤษภาคม 2555 21:13
     
     

    Before getting into all of this, I always start with my standard disclaimer of “I’m not a database guy!” and for the most part, that’s true. I suppose if anything, I’d be a lightweight contender in the ring; many here are the real deal – but I’m not one of them!

    I couldn’t even tell you what some of the words mean that I see them use, and if you were to ask me about an SQL Transact something-or-other, I’d give you a blank stare.

    I say all of this because I don’t want you to think that what you might read is necessarily coming from an experienced authority in databases. I’ve learned a few things and that’s what I share here, but just to set the record straight, I wanted to preface the rest of this with that statement. :)

    The Data

    The data itself as at the heart of all of this, and so is the rightful beginning of the discussion regarding the program that uses it.

    In my program, the data is no longer in MS Access, but rather uses SQL Compact. If you don’t have that, then I would strongly encourage you to install it (it’s free) and you can do that by having a look at this link.

    I’ll leave to you to peruse around and find the many comparisons that have been made between SQL and Access, but in short (and this is just my opinion), SQL of any sort is simply a better tool for the job.

    One thing that I very much like about it – which wasn’t the case when I was using Access 2007 – is that there are no prerequisite requirements on the part of your end users. You’ll distribute a small handful of .dll files (seven, plus one additional one that you already have but you’ll need to set to be copied to the \bin\Release folder during the build), and you’re good to go; your users will have no problem opening the program and doing anything with the data that you’ve given them the ability to do.

    Moving on to the matter at hand, the name of the database and the table name are identical to yours; the fields (columns) are, for the most part, like yours but there are some changes:

    The first thing that’s different is that unlike yours, the field “CompanyID” is not the primary key in this one; I have a separate field (“IDX”) that I’m using for that. IDX is a type BigInt which in our world would be the equivalent of a type “Long”. It’s set as an identity and that’s mainly why I chose to set it up this way and use it as the primary key. This way, we don’t have to ‘do’ anything; it’s automatic and will increment itself to always be unique.

    The second thing that I’d like for you to notice – and this is the first of two main anomalies that I found – is that there is no longer a field named “Region”. In fact, I don’t know how, in your program, this didn’t create a problem and may in fact be the basis of the issue with the ListView.

    The word “Region” is a reserved word in VB so we can’t use it for a field (column) name.

    Getting The Sample Data Into My SQL CE Database

    The first thing that I did – unseen in any of this – was to create a program that I used to transfer your sample data into the new SQL CE database table, and I had a problem right off the bat doing that:

    It couldn’t read the field in yours called “Region”. It showed it the dataset, but any attempt to get the data from that field just plain failed; it didn’t recognize it, and the reason was the name of it wouldn’t be honored by VB (again, because it’s a reserved word in VB).

    I modified yours to match mine, brought it back in, then I could read the data from it once I updated everything.

    The second problem that I ran into was something not uncommon but something that you need to know to avoid: VBNull.

    There are good uses for a null; but unless you’ve specifically set everything up to know that, it will plague your program will problems. In my mind, I just don’t use it period! Having said that though, have a look again at the screenshot above. I have them set up (their default) to accept a null.

    In code, however, I will prevent this from ever being the case; I’ve just pulled my hair out so many times over that damned VBNull that I walk BIG circles around ever allowing it to happen, period!

    OT: Some weeks back, in another thread, David Rice explained a great example of where a null comes in handy. The example he used was about having a field for Date Of Death and the question was: “How do you handle that for a person who’s still alive?”. The answer he suggested was the null. I certainly won’t disagree, but until such time that I have to use it, I’m not going to!

    Once I set up a condition on all fields to check that there actually was something there (that it wasn’t “nothing”), and set a default if that was the case (that’s why you’ll see the “- -“ in some of the data), then I managed to get the data from your sample into mine.

    All of these fields are type string – the same as they are in yours. Do understand that an empty string (“”) is not the same as a null. Null is nothing; an empty string is a string with nothing in it, but that’s the same thing.

    I’ll next explain the program’s code in the thread(s) following this one.


    Please call me Frank :)

  • 13 พฤษภาคม 2555 21:14
     
     

    The Code To Make All This Work

    Someone in this forum has a signature that says something like “still lost in code, only at a higher level” and boy I sure can appreciate that! ;-)

    A few weeks ago, I posted something here that, while long, is also the basis of this program so I hope you’ll take a few minutes to have a look at it. In another thread – which I unfortunately didn’t keep track of – I set up something to allow for multiple filters to be used and that’s also used in this program for filtering, although I’ve embellished it now.

    Throughout this, you will see the use of LINQ-To-SQL to a fair amount. I’ve come to use that only recently and even though I’m a novice at it, I have to say that I’m thoroughly impressed with it. It’s odd to work with and the syntax will make you cross-eyed, but once you get the hang of even the basic stuff (which is my present level), you’ll find it to be a very powerful tool to use.

    There are three forms, and the code for each are shown in pages on my website:

    Form1

    AddCustomer

    FilterData

    The code isn’t very well documented, so I’ll explain the big parts of it in this. For the most part, it already should be fairly straightforward but there a few things that I need to explain, including some things where I just simply had to guess at because I don’t know your ‘business rules’, etc..

    The first thing that I’d like to explain is the use of two class-level variables in Form1, shown here:

    Private dbHasErrors As Boolean = False

    Private dbIsUpdating As Boolean = True

    The variable “dbIsUpdating” is simply a way that I instruct the program (in various events) to NOT proceed if in fact it’s logical true. The first use is when the database is being updated because when the data is updated (saved), it will call the TableAdapter’s .Fill method. This of course will cause various events to fire and I don’t want them to until that operation is complete.

    You’ll notice that it’s initially set to logical true and only set to false near the end of the of the form’s load event. This allows the initial fill to take place without causing the events to run the code that I have in the subs of those event handlers.

    The variable “dbHasErrors” is a way that I’m able to know on a class-wide level if there are problems being reported in the validation (in Form1 that would be the case if/when they go to edit the data).

    Data Validation

    There are two main “ways” validation can be done: Form level (what I have) and Dataset level. The idea of Dataset level validation is that you can create a set of rules that are carried in the dataset itself; do it one place and in all instances, the business rules are enforced.

    Great idea! But I don’t get it … I’ve looked into it before but frankly it left me befuddled (what they call a column seems to me to be a row and vice versa) so I’ve resigned to doing everything at the form level.

    The drawback is, of course, that it [may] need to be repeated with multiple forms. That’s not quite the case here, although it’s similar. Remember my adamancy about “no nulls ever!” from the last thread?

    When the user goes to add a new customer, the way that I’m able to prevent this starts with this class declaration:

    Public Class Customer

       Public CustomerID As String = "--"

       Public CompanyName As String = "--"

       Public CompanyAddress As String = "--"

       Public CompanyCity As String = "--"

       Public CompanyCountry As String = "--"

       Public CompanyPostalCode As String = "--"

       Public CompanyRegion As String = "--"

       Public CompanyPhone As String = "--"

       Public CompanyFax As String = "--"

       Public ContactName As String = "--"

       Public ContactTitle As String = "--"

    End Class

    An instance of that class is used when they go to add a new customer. Using the defaults that you see there, if they don’t put the information in (and if it’s not a required field), then I put it in for them, and that’s how I avoid nulls. It will always only be either what they’ve set or the defaults of what you see above, and therefore no nulls - - ever!

    Back to the use of the class-level variable “dbHasErrors”, when the validation occurs and an error is spotted, this variable is set to logical true. When they close the form, if there are unsaved changes, it will prompt them to save it prior to closing the program, but what if there are errors?

    You don’t want to have the program save erroneous information so that’s how I check to see if any exist and, if so, they automatically lose the unsaved changes when closing the program, and while still in the program, they are prevented from saving it by disabling the “Save Data” button.

    Back to validation in the program though, in both the AddCustomer form and in Form1, I’m using an ErrorProvider to show the validation error (if one exists) to the end user. There’s one in your toolbox; just grab it and drag to your form and you’ll see it in the components tray in Design View.

    If you look at the Validation Event (it’s a single event handler sub with multiple handles) in Form1 then look at the same in the form AddCustomer, they look very similar; this isn’t a coincidence.

    I set up the validation in AddCustomer then, because the controls have the same name as in Form1, I was able to copy it verbatim over to Form1. Of course I had to make changes but by and large, that became the backbone structure of what you see in Form1’s validation.

    Please take particular note to what I’m doing regarding validation with the CustomerID. I simply don’t know what you have mind there, but whatever the case, you can modify the routine (in both) to ensure that the user does it like you have mind.

    It appears that all of them in your sample data have exactly five (5) characters, all are upper-case alpha characters (no numbers), and all are unique. In my validation though, the only thing that I check for is that it’s unique; anything else is not checked.

    Whatever your business rules are though, you can enforce them in that routine. If you want me to help you with it, then explain what the “rules of the road” are and I can modify it, but I’m hopeful that you’ll take this and try to alter it yourself.

    Note also that in AddCustomer, it uses a LINQ query and tests to see if the resultant dataset count is greater than zero, but in the same one in Form1, it checks to see if the count is greater than one, not zero. Is this a mistake?

    Not at all: In the form AddCustomer, nothing is bound to anything – it simply looks back at the dataset on Form1 to see if a particular CustomerID (in any case, upper-case, lower-case, or mixed-case) exists. If the count is anything above zero then it exists and cannot be reused.

    On the other hand, in Form1, that’s not so. Let’s say, for instance, that you focus a TextBox on Form1, then tab off that TextBox to another one. This would trigger the Validating event and in that event, if it were only look for a count greater than zero, you’d see the ErrorProvider show up and then lock you into changing it!

    “This one already exists”

    Well no kidding it exists – itself!

    “Sorry, rules are rules, you have to change it now”

    See?

    So of course it exists in one place – the data itself has it, and given that, checking for a count of greater than zero isn’t viable; in Form1 we have to test for a count greater than one instead.

    Understand one thing here also because, if you don’t, then it will surely be confusing: The validation is looking at the dataset which is the in-memory cache of the data, not the data from the database file (which may or may not be the same).

    My point here is that as soon as you change it in any way, the dataset data has changed right along with it. I hope that makes sense? As an example, let’s say that I have only two records (rows). The first one has a CustomerID of “ABC” and the second one has a CustomerID of “ABD”.

    I’m on the first row and I go to change “ABC” to “ABD”. As soon as I backspace the “C” and change it to a “D”, the CustomerID of “ABC” no longer exists in the dataset.

    When validation takes place as I go to leave it, however, “ABD” now exists in two places (the second row and now this one) and the count will be 2. As such, it will trigger the routine to disallow this, show the ErrorProvider, and lock the user into the control (the TextBox) forcing them to change it to something unique.

    The validation event of both forms looks to see that five things are present:

    • Customer ID
    • Company Name
    • Address
    • City
    • Country

    This may or may not be what you want as minimum for adding a new customer but hopefully you can look at what I’ve done and modify it if it’s not what you want.

    In the validation event handler, it will first determine which TextBox the sender is (ergo, “who’s knocking on the door”) and it really only looks to see if it’s the CompanyID TextBox or one of the other four.

    If it’s one of the other four, you’ll see a somewhat odd looking set of things there using LINQ. The purpose is to do this: When a user either adds a new customer or edits one, the primary objective is to prevent duplicate data. Obviously they can’t have the CompanyID that another one has and we’ve covered that, but what if a simple typo allows them to add duplicate information?

    As an example:

    • Tom’s Pizza
    • tom’s pizza
    • tOm’s       pIzZa

    All of those really are the same but ordinarily a computer program would see them each as being different. The routine that you see in the code will see them as being the same and it does this by first stripping out any space characters (if they exist) then change what’s tested to lower-case. It does the same on what’s being tested in the dataset, then makes the comparison.

    It looks for the combination of the four remaining minimum required fields the same way (for a given customer) and then the program tests for its existence. It’s a bit roundabout but I think it’s worth the effort.

    Finding And Filtering

    In the sections regarding those, it makes extensive use of LINQ-To-SQL and the result is a fairly fast way that it’s able to do what it does.

    Note with the filtering that it actually changes the datasource/databindings for the various controls, then when they choose to see them all again, it changes them back.

    I’ll leave to you to explore that area and ask questions if you have any.


    Please call me Frank :)

  • 13 พฤษภาคม 2555 21:14
     
     

    Summing Up

    I won’t go into all the details beyond this point, mainly because I don’t yet know if you’re even interested in what I’ve shown. But if you are – even just some portions of it – then you may want start by downloading the project folder from here and using that as your basis.

    There are still things to do in that program to make it more robust. For instance, what if the user were to enter information that’s longer in character count than the data allows? All sorts of things can happen along the road, so think them through, disallow what you can (the example I just used, for instance, has a very simple fix) and then selectively use Try/Catch blocks for the unknown so that you handle them gracefully.

    I still don’t know what the problem is with you ListView; it’s perplexing, but I hope that you’ll give some thought to tossing it aside in lieu of what I think is a better way.

    I hope this has been helpful. :)


    Please call me Frank :)

  • 14 พฤษภาคม 2555 13:42
     
     

    Hi Frank,

    Thank you very much.  If it can be done with less headache, I am down with that.   Let me download the file and take a look at it. 

    Thanks,

    Bob

  • 14 พฤษภาคม 2555 13:58
     
     

    Hi Frank,

    I opened up one of the links that you mentioned in your posts and you mentioned something about "SQL CE installed"  Do I need to installed this on my local machine?  I am still trying to download the zip file.  Will let you know how it turns out.

    Thanks,

    Bob

  • 14 พฤษภาคม 2555 14:05
     
     

    Hi Frank,

    I opened up one of the links that you mentioned in your posts and you mentioned something about "SQL CE installed"  Do I need to installed this on my local machine?  I am still trying to download the zip file.  Will let you know how it turns out.

    Thanks,

    Bob

    Bob,

    On mine I did have to install it but I run VS2008. If you're using VS2010, then it's possible that's already installed (I just don't know). If you try to run it in debug and it throws an exception right off the bat, then you know that it's not installed. Try that first and let me know please?


    Please call me Frank :)

  • 14 พฤษภาคม 2555 14:10
     
     

    Hi Frank,

    I am using 2008 and I do not have SQL CE installed on my machine.  Will let you know.

    Thanks,

    Bob

  • 14 พฤษภาคม 2555 14:16
     
     

    Hi Frank,

    I am using 2008 and I do not have SQL CE installed on my machine.  Will let you know.

    Thanks,

    Bob

    You'll almost surely need to install it and you can download it (it's free) from here:

    http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=5821


    Please call me Frank :)

  • 14 พฤษภาคม 2555 14:22
     
     

    Hi Frank,

    I downloaded & ran it.  I received errors that stopped at Me.CustomersTableAdapter.Fill(Me.SampleDataSet.Customers) <- FileNotFoundException as unhandled (Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dendencies. The system cannot find the file specified.)  I guess my version of SQL CE is older than yours???  Let me download it and install it.  Will let you know.

    Thanks,

    Bob


    • แก้ไขโดย LA_Bob 14 พฤษภาคม 2555 14:26
    •  
  • 14 พฤษภาคม 2555 14:25
     
     

    Hi Frank,

    I downloaded & ran it.  I received errors that stopped at Me.CustomersTableAdapter.Fill(Me.SampleDataSet.Customers) <- FileNotFoundException as unhandled (Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dendencies. The system cannot find the file specified.)  I guess my version of SQL CE is older than yours???

    Thanks,

    Bob

    I don't know, honestly. Did you install it from the link I posted a minute ago? If so, you might want to run Windows update and see if there might be something showing up but that's where I originally installed mine from.

    Please call me Frank :)

  • 14 พฤษภาคม 2555 14:53
     
     

    Hi Frank,

    Dang.  I downloaded & installed SQL CE.  I opened the program and there was no errors. It ran good with no errors or warnings

    This is new to me..... how do I open up the sample SQL server CE (database) and see the data.  Also, I want to know how to set it (transfer) up data in ".txt" to this type of format.

    I have this question for you and it might be a bit way ahead of the game here.  Can you deploy the program along with SQL CE (database)? Wil You show me how to do this?

    Thanks,

    Bob.



    • แก้ไขโดย LA_Bob 14 พฤษภาคม 2555 15:00
    •  
  • 14 พฤษภาคม 2555 14:57
     
     

    Hi Frank,

    Dang.  I downloaded & installed SQL CE.  I opened the program and there was no errors. It ran good with no errors or warnings

    This is new to me..... how do I open it up and see it.  Also, I want to know how to set it (transfer) up data in ".txt" to this type of format.

    I have this question for you and it might be a bit way ahead of the game here.  Can you deploy the program along with SQL CE (database)? Wil You show me how to do this?

    Thanks,

    Bob.


    Sure, give me about an hour or so and I'll put something together to show you.

    Please call me Frank :)

  • 14 พฤษภาคม 2555 15:32
     
     

    Can you deploy the program along with SQL CE (database)? Wil You show me how to do this?

    Thanks,

    Bob.



    Ok, to deploy them, start by doing this. In Solution Explorer, double-click "My Project":

    Once that opens, click on the "References" tab and you'll see this:

    Notice the one highlighted above (System.Data.SqlServerCe) is shown as False for "Copy Local". You need that set to true, so when you click on it, look in the properties and change it to "True":

    Now build the program. That will then put everything in the \bin\Release folder but you still need the seven .dll files from SQL CE itself. You have them, you just don't know it yet. If you'll look where it installed, you'll see them:

    The files that I show highlighted there need to be deployed with your application. I usually just copy them over to the \bin\Release folder to have everything in one place, but that's up to you.

    Please call me Frank :)

  • 14 พฤษภาคม 2555 15:52
     
     

    Hi Frank,

    Cool.  I like that.............  How do I open up the sample SQL server CE to see the data?  Also,  How do I setup/transfer data from ".txt" file to SQL server CE?

    Thanks,

    Bob.

  • 14 พฤษภาคม 2555 16:08
     
     

    Hi Frank,

    Cool.  I like that.............  How do I open up the sample SQL server CE to see the data?  Also,  How do I setup/transfer data from ".txt" file to SQL server CE?

    Thanks,

    Bob.

    First part first, viewing your data: In the Data Sources window, right-click on the table then click on "Preview Data":

    In this case, you can then see the data by clicking the "Preview" button:

    Now here's the bad news - normally that won't work! The reason is that it's not looking in your \Debug folder for that view, it's looking in the main folder for it and normally, that's a "blank copy" so that's all you'd see.

    I know it took me a while to get used to that because with Access I could just double-click the file and it'd open with Access so I could then have a look around. The only thing I've found, if I *really* need to see the data, is that I'll create a little test routine somewhere so that I use the program itself to let me see what's what.


    As for your other question about a text file into a data table, you'll need to tell me more about what's in the text file. Is it a .csv or ...?


    Please call me Frank :)

  • 14 พฤษภาคม 2555 17:24
     
     

    Hi Frank,

    Text file is like notpad text file.  I wonder how you transfer data from it to SQL server CE.

    Thanks,

    Bob

  • 14 พฤษภาคม 2555 17:30
     
     

    Hi Frank,

    Text file is like notpad text file.  I wonder how you transfer data from it to SQL server CE.

    Thanks,

    Bob

    I think you're asking how you would store it in the SQL CE database? In other words, the equivalent of "memo" type field in Access, right?

    If so, and you'll want this as a future reference anyway, have a look at this:

    http://msdn.microsoft.com/en-us/library/ms172424(v=sql.100).aspx

    You can use the ntext type field for that.


    Please call me Frank :)

  • 14 พฤษภาคม 2555 17:36
     
     

    Hi Frank,

    Let me put together something and make a screenshot of it and upload it to show you what I mean by text file.  Will be back.

    Thanks,

    Bob

  • 14 พฤษภาคม 2555 18:09
     
     

    Hi Frank,

    Please take a look at screenshot below.  This is what I mean by text file.

    Is there a way that we can transfer data from text file like this to SQL server CE?

    Thanks,

    Bob.

  • 14 พฤษภาคม 2555 18:15
     
     

    Hi Frank,

    Please take a look at screenshot below.  This is what I mean by text file.

    Is there a way that we can transfer data from text file like this to SQL server CE?

    Thanks,

    Bob.

    Yes, and that goes back to my initial question earlier. Is the text comma-delimeted or tab-delimited or just what? Whatever the delimeter, you can use a TextFieldParser and tell it what to use for the delimeter, or you can use a StreamReader and split each line of text based on that delimeter. Then, per line, you'd add a new row in the datatable based on those elements.

    Looking again at the screenshot, it can't be a comma-delimted because I see a comma in some of the text, so my guess is tab-delimited.

    Be sure that you test that it's not the first line (the header row) and that each line actually has something in it and, further, that it has the correct number of elements (fields). If you're dealing at all with any sort of math in any of it, use the TryParse to handle times when it can't be converted and, if that's the case, give it a default (typically 0).


    Please call me Frank :)

  • 14 พฤษภาคม 2555 18:47
     
     

    Hi Frank,

    I played with the program a little bit and this is what I have found so far.  When I selected an item on the main form and all of the textbox populated good.  No problem here.  Save Data button is activated after you make changes to at least two characters.   Can you make it to activate for just one character?

    Thanks,

    Bob

  • 14 พฤษภาคม 2555 18:53
     
     

    Hi Frank,

    I played with the program a little bit and this is what I have found so far.  When I selected an item on the main form and all of the textbox populated good.  No problem here.  Save Data button is activated after you make changes to at least two characters.   Can you make it to activate for just one character?

    Thanks,

    Bob

    Unfortunately not - it's the nature of the beast, but if you leave it (move to another control), then it will recognize it and of course this includes closing the form which it should also catch even after just one text character change.

    Test that please?


    Please call me Frank :)

  • 14 พฤษภาคม 2555 18:55
     
     

    Hi Frank,

    The screenshot is what I put together and it is tab-delimeter and spacebar, etc.  I wanted to show you what it would look like in the text file.

    For the real one, I am not sure what delimeter it is......... the program outputs something is similar to that. 

    So my question is how do I transfer data from the text file into SQL server CE?  Does that mean I will have to write a program to read this text file and write the data to the SQL server CE or what?

    Thanks,

    Bob

  • 14 พฤษภาคม 2555 19:00
     
     

    Does that mean I will have to write a program to read this text file and write the data to the SQL server CE or what?

    Yes - no other way to do it with this one.

    Please call me Frank :)

  • 14 พฤษภาคม 2555 19:09
     
     

    Hi Frank,

    I tested that for two or three times and Yes. it did detect the changes and asked if I wanted to save it.  That is a cool.

    With a program setup this way,  can I still be able to write SQL statement just like Access Database setup?  If so, can you give me an example how to write an SQL statement?

    Thanks,

    Bob.

  • 14 พฤษภาคม 2555 19:13
     
     

    Hi Frank,

    I tested that for two or three times and Yes. it did detect the changes and asked if I wanted to save it.  That is a cool.

    With a program setup this way,  can I still be able to write SQL statement just like Access Database setup?  If so, can you give me an example how to write an SQL statement?

    Thanks,

    Bob.

    Ha! I don't even know what an SQL statement is!

    That's what I meant in my write up about "I'm not a database guy"; it' out of my league at that point. You might want to start another thread - maybe even reference this one - and ask there. Honestly this thread is already quite long so you might want to do that anyway.

    I'm sure it can be done, don't get me wrong, but I'm just in no way the guy to answer it! ;-)


    Please call me Frank :)

  • 14 พฤษภาคม 2555 19:16
     
     

    Hi Frank,

    How did you transfer/convert microsoft access database to this SQL server CE?   I can transfer data in text file to microsoft access and use method that you did (in this example) to convert to SQL server CE. 

    Thanks,

    Bob.

  • 14 พฤษภาคม 2555 19:21
     
     

    Hi Frank,

    How did you transfer/convert microsoft access database to this SQL server CE?   I can transfer data in text file to microsoft access and use method that you did (in this example) to convert to SQL server CE. 

    Thanks,

    Bob.

    I wrote a program that did it but I've since tossed it away. It's not that hard once you get the hang of it.

    Please call me Frank :)

  • 14 พฤษภาคม 2555 20:36
     
     

    Hi Frank,

    I guess my hope is just gone with the wind ......... :) .............. I was thinking that I was going to "mark as answer" very soon here...... Well, I guess I just go back to where I started ....... :)

    Thanks,

    Bob.


    • แก้ไขโดย LA_Bob 14 พฤษภาคม 2555 20:38
    •  
  • 14 พฤษภาคม 2555 20:41
     
     คำตอบ

    Hi Frank,

    I guess my hope is just gone with the wind ......... :) .............. I was thinking that I was going to "mark as answer" very soon here...... Well, I guess I just go back to where I started ....... :)

    Thanks,

    Bob.



    Notwithstanding the mark as answer (but the thread is long enough now that I do hope you'll close it soon) ... why? I thought you liked what I did and agreed that it's a better way?

    Please call me Frank :)

    • ทำเครื่องหมายเป็นคำตอบโดย LA_Bob 14 พฤษภาคม 2555 20:58
    •  
  • 14 พฤษภาคม 2555 20:57
     
     

    Hi Frank,

    I will mark it as answered here.  I did like it but since I am not familiar with SQL server CE and how to manipulate data to do what I want for this project ... I am not sure if I can continue on with it.  There are a whole lot more than just that one screen with a few functions (add/update/delete).  In fact, that is just one fifth of the project and other parts of the project is a little bit more complicated.  BTW,  Thank you very much for your time and showing me the alternative. 

    Thanks,

    Bob.

  • 14 พฤษภาคม 2555 21:15
     
     

    Hi Frank,

    I will mark it as answered here.  I did like it but since I am not familiar with SQL server CE and how to manipulate data to do what I want for this project ... I am not sure if I can continue on with it.  There are a whole lot more than just that one screen with a few functions (add/update/delete).  In fact, that is just one fifth of the project and other parts of the project is a little bit more complicated.  BTW,  Thank you very much for your time and showing me the alternative. 

    Thanks,

    Bob.

    Let me clear my head here ...

    First of all, the question was about a ListView and in no way did my "better way" answer the question about a ListView. I still don't know what's wrong with it but normally, my very first answer would have worked. I took this thread off-topic when I added what I did yesterday, but as to the question at hand - the ListView find - what I offered surely doesn't answer that.

    Secondly though, I think you're misunderstanding. What I showed absolutely WILL work with an Access database! Not as you presently have it -- one field name ("Region") will need to be renamed and another field ("IDX") added, set to autoincrement, and made the primary key but beyond that, it absolutely WILL work!

    I am concerned, however, about your nulls. With no more rows in it than it has, it's not hard to fix though: Open it in Access and every place that you see a blank spot, type something (anything). You can even backspace it out if you want, but it needs to "not be nothing" which is a null.

    Beyond that, what I showed will work for Access or SQL or even an old dBASE database (not 100% sure on the dBASE but I think so).

    If you do decide to start all over again - and I've done that a thousand times if I've done it once - don't toss the methods that I used aside; they will work, and yes I promise so!


    Please call me Frank :)

  • 14 พฤษภาคม 2555 23:43
     
     
    Do you mind if I use this sample data and this program for future reference, or would you prefer that I didn't?

    Please call me Frank :)

  • 15 พฤษภาคม 2555 0:00
     
     

    Hi Frank,

    Thank you for your work & time that you put into this.  I really appreciate your work and I mean it.

    So you do know a thing or two about using Microsoft Access database with VB.  I guess you just don't like it or don't want to use it for one reason or another. Again, thank you for your hard work.  You have a good night.

    Thanks,

    Bob.

  • 15 พฤษภาคม 2555 0:09
     
     

    Hi Frank,

    Thank you for your work & time that you put into this.  I really appreciate your work and I mean it.

    So you do know a thing or two about using Microsoft Access database with VB.  I guess you just don't like it or don't want to use it for one reason or another. Again, thank you for your hard work.  You have a good night.

    Thanks,

    Bob.

    You still never answered the question though - if you'd prefer that I not use it then I'll remove what I posted yesterday as it's pointless to keep it on here and frankly, has nothing to do with a ListView.

    "...you just don't like it..."

    Bob - look around, don't take my word on it, do a Google search for Access compared to SQL. I'm not alone in my thoughts. I might not 'be a database guy' but I can tell you first-hand from real experience that once you get above about ten-thousand rows (or less than that depending on how many columns you have and/or what those columns contain), Access will do some weird things. You'll do something and you'll see the program freeze totally - you look down to your hard drive light and it's "steady on". Is it something you did? NO - it's Access trying to grab its brains again.

    To each their own my friend and the methods I showed are something I hope you'll hang on to because they'll work for whatever you choose to use.

    I often post things that I'd like to show others when questions come up, and thus my query to you: May I use this to show others, or would you prefer that I not?


    Please call me Frank :)


  • 15 พฤษภาคม 2555 0:37
     
     

    Hi Frank,

    I am sorry for not answering your questions................. honestly, I do like what you presented here and I would love to use it if I could figure out how to manipulate the data to make it work the way the project required.  That is number one.  Number two, I don't know how to convert/transfer the data from text file to SQL server CE............  I do not know how or where to begin with it and yes, I am being honest with you on this.  I understand that you told me a little bit on this but I still don't don't where to begin.    If you help me get started and along the way if I get stuck, I would love to move on to something new and better.   I would love to make my project work using SQL server CE if you don't mind help me out from start to finish and/or when I get stuck. So, Would you be my teacher?

    Thanks,

    Bob.

    Yes.  I have heard the limitation of the Microsoft Access database...............I guess I get stuck with this if I do not know anything else..........


    • แก้ไขโดย LA_Bob 15 พฤษภาคม 2555 0:38
    •  
  • 15 พฤษภาคม 2555 0:46
     
     

    Ha!

    Me - a "teacher" with databases! Now that's downright comical!

    But to answer, sure - I'll do what I can anyway and I have done at least some of it.

    Can you upload the text files to the same FTP area that I have in the post waaaaaaaaaay up there from last Friday? If you can then I'll have real data that I can work with and I'll show you what I did to get it into the datatable(s). How many are there?

    Do you want me to revert to using Access? I still have it - it's just not (again, in my opinion) the best choice for a host of reasons.

    Lastly, can you give me a little more detail about the big scheme of things? You said that this is a small portion of it all; obviously I have no way to know. If it's confidential information then I understand that also of course.


    Please call me Frank :)

  • 15 พฤษภาคม 2555 0:57
     
     

    Hi Frank,

    I would like it to be in SQL server CE, so that i can learn it as the same time.

    It is a work's project and I am not sure if I can post it on the web or make it public.  Let me say this, let me find some data that "kind/sorta" like the real one and put it together and I will send it to you (post it to your ftp site as I did the last time).   I don't think it will happen tonight but I will try to do it tomorrow (I am not sure when it will be available tomorrow).  Please be patient with me on this and will post it to your ftp site.  Thank you very much.

    Thanks,

    Bob.


    • แก้ไขโดย LA_Bob 15 พฤษภาคม 2555 0:58
    •  
  • 15 พฤษภาคม 2555 1:08
     
     

    Hi Frank,

    I would like it to be in SQL server CE, so that i can learn it as the same time.

    It is a work's project and I am not sure if I can post it on the web or make it public.  Let me say this, let me find some data that "kind/sorta" like the real one and put it together and I will send it to you (post it to your ftp site as I did the last time).   I don't think it will happen tonight but I will try to do it tomorrow (I am not sure when it will be available tomorrow).  Please be patient with me on this and will post it to your ftp site.  Thank you very much.

    Thanks,

    Bob.


    Sure, I understand.

    I'm a mechanical engineer - not a developer; I started learning VB (actually a longer history than I'm saying, stemming back to the mid 80's with dBase), but I always knew that I could broaden my horizons by having the ability to create a program that would do things for me. That's how it started and continues to be something that I enjoy doing.

    I'm only saying that it's not really my forte, but we do all learn in time - and I've picked up a few things along the way.

    I'll show you how but briefly, think of how we'll do this with the text file. Once we know what the delimeter is (and that's crucial), we'll read the text file as text, line at a time. On each line, there's information - or maybe not.

    The first line we have to toss aside because it's the header information (assuming it's included in the text file) and each line that we process, we need to see first if it's a blank line. If it is, ignore it and move on, but if not, read that information in from that line (and only that one line), parse it based on the delimeter, test that it has the correct quantity of fields (sounds stupid but trust me on this one and a null will NOT pass this test) and then, using that information, we'll then create a new row of data in our datatable and, field at a time, add it, add the row, and move to the next.

    Sounds like a lot huh? It's not ... not really. If you have a million lines of stuff then it might be worth looking at threading but otherwise, it'll suprise you how quickly it can do all of that.

    Anyway, I look forward to seeing what you send. I do have to tell you though that I'm involved in a "real work" project most of the day so if I'm long in replying, it's because of that and not because I'm ignoring you.


    Please call me Frank :)

  • 15 พฤษภาคม 2555 1:26
     
     
    Hi Frank,



    I will post a message here tomorrow to let you know it is available as soon as I post it to your ftp site.

    Thanks,
    Bob.
  • 15 พฤษภาคม 2555 21:06
     
     

    Hi Frank,

    It has been a hectic day today.  I am sorry I haven't been able to put together an example yet.  I will try to do it tonight and tomorrow and I will post it on your ftp site tomorrow night.  I will post a message here when it is available on your site.  I guess you just need a few lines to see what the table looks like??

    Thanks,

    Bob.

  • 15 พฤษภาคม 2555 21:16
     
     

    Hi Frank,

    It has been a hectic day today.  I am sorry I haven't been able to put together an example yet.  I will try to do it tonight and tomorrow and I will post it on your ftp site tomorrow night.  I will post a message here when it is available on your site.  I guess you just need a few lines to see what the table looks like??

    Thanks,

    Bob.

    Well the real starting point will be to know the name of the tables and, per table:

    - The name of the field (column)
    - The type field
    - If text, the maximum length, if numeric the type data (think in terms of integer, double, long, etc.)

    Once I get information back from an architect (which I'm hopeful will be tomorrow), I'll have my hands full for several days so please do understand that also.


    Please call me Frank :)

  • 17 พฤษภาคม 2555 2:03
     
     

    Hi Frank,

    I am sorry for late reply.

    I just remember something............ I have been tweaking around with the program that you did with SQL server CE for a few days and they are kinda similar in a way (or at least that is what I am thinking....) with my project. So may be (or may be not but I would like to give it a try.....) this an opportunity for me to learn and work on it using that program to help with my project.  Here is what I need help with before I can start it working on it,  I need your help on how to convert from Microsoft Access to SQL server CE.  I can convert from text file to Access, but I need help to convert it from Access to SQL server CE.  Would you please help me with that conversion?  Once it is converted, I will start working on my project for a few days (while you are away to work on your work.) Hopefully, I will have something to show you when you are available.  I am looking forward to hear from you.

    Thanks,

    Bob.

  • 17 พฤษภาคม 2555 14:33
     
     

    Hi Frank,

    I am sorry for late reply.

    I just remember something............ I have been tweaking around with the program that you did with SQL server CE for a few days and they are kinda similar in a way (or at least that is what I am thinking....) with my project. So may be (or may be not but I would like to give it a try.....) this an opportunity for me to learn and work on it using that program to help with my project.  Here is what I need help with before I can start it working on it,  I need your help on how to convert from Microsoft Access to SQL server CE.  I can convert from text file to Access, but I need help to convert it from Access to SQL server CE.  Would you please help me with that conversion?  Once it is converted, I will start working on my project for a few days (while you are away to work on your work.) Hopefully, I will have something to show you when you are available.  I am looking forward to hear from you.

    Thanks,

    Bob.


    Bob,

    I suspect that you’re looking for an import “tool” that will do this for you but there is none. There’s lots of things about Access that I like and frankly miss by using SQL CE, but it is what it is.

    I’ve put an example together for you to show you “how I do it” (emphasis on that – that doesn’t mean there aren’t other ways, possibly even better/shorter ways). Let me explain, first, what I have so you’ll know what’s going on:

    A little more than a year ago, I bought a zip code data list. They sent it as a .csv file (I think, although it may have been a tab-delimited text file) and as you know, I can directly import that into Access which I was still using then.

    I’m going to use that Access 2007 file and, with it, create a SQL CE file. Be sure to read the notes about the data in the program code which can be viewed here.

    The starting point is that you have to set up your new datatable in SQL CE and there’s nothing automatic about it. I’ll usually take a screenshot like you see below:

    …then I’ll print it out or maybe just open it and minimize it, then using that as a basis, I create the table as shown here:

    It’s more or less the same thing (although I didn’t set the text length, which I should, honestly). I’ve made one change and that’s to a field that contains “Y” or “N” in the original to indicate whether or not that the city subscribes to daylight savings time. In the new table, I’m setting that to be a type “bit” which is how we can do the equivalent of “Yes/No” in Access. In the code, you’ll see how I’m setting it up.

    I’ve tried to comment the code fairly extensively so hopefully you’ll understand what I’m doing there and why, but if you’re unclear on any of it, just ask.

    If you want, I have the entire project folder (including the original Access database) zipped up and you can download it by clicking this link.


    Please call me Frank :)

  • 18 พฤษภาคม 2555 18:00
     
     

    Hi Frank,

    I cannot find SQL server under Servers in the Server Explorer and I cannot create an empty table (.sdf) in my project?

    I have visual studio 2008 and Microsoft SQL server 2005 and SQL server Compact Edition installed on my computer.  Under Add New Item, I have Local Database, Service-base Database and Local Database Cache listed.  What am I missing?  Do I need to install anything?

    Thanks,

    Bob.

  • 18 พฤษภาคม 2555 18:06
     
     

    Hi Frank,

    I cannot find SQL server under Servers in the Server Explorer and I cannot create an empty table (.sdf) in my project?

    I have visual studio 2008 and Microsoft SQL server 2005 and SQL server Compact Edition installed on my computer.  Under Add New Item, I have Local Database, Service-base Database and Local Database Cache listed.  What am I missing?  Do I need to install anything?

    Thanks,

    Bob.

    You won't be able to use that.

    Have a look at this thread where I explain it step-by-step:

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/d53b58a5-85b8-4976-8c5c-db7f505597a9/#9b6ab34b-88a4-4428-a086-74ebbefd6f83


    Please call me Frank :)

  • 18 พฤษภาคม 2555 18:47
     
     

    Hi Frank,

    Thank you for your quick response.  How come I don't even have the same window as yours?

    When I right click on Data Connection and select Add Connection, my Add connection window does not automatically select Microsoft SQL Server Compact 3.5. In fact it is not even listed in Change Data Source when I selected Change button.  In Change Data Source window, there are Microsoft Access Database File, Microsoft ODBC Data Source, Microsoft SQL Server, Microsoft SQL Server Database File, Oracle Database and other.  That is all listed in Change Data Source window.  Also, in the Add Connection window, it does not have Data Source and Connection Properties sections.  How come my is so different than yours?  Am I missing something here?

    Thanks,

    Bob.

  • 18 พฤษภาคม 2555 18:49
     
     

    Hi Frank,

    Thank you for your quick response.  How come I don't even have the same window as yours?

    When I right click on Data Connection and select Add Connection, my Add connection window does not automatically select Microsoft SQL Server Compact 3.5. In fact it is not even listed in Change Data Source when I selected Change button.  In Change Data Source window, there are Microsoft Access Database File, Microsoft ODBC Data Source, Microsoft SQL Server, Microsoft SQL Server Database File, Oracle Database and other.  That is all listed in Change Data Source window.  Also, in the Add Connection window, it does not have Data Source and Connection Properties sections.  How come my is so different than yours?  Am I missing something here?

    Thanks,

    Bob.

    Oh boy -- yow.

    I don't know. You might want to use the link I gave you as reference and post a new question to ask just that. I have no idea why that's so!


    Please call me Frank :)

  • 18 พฤษภาคม 2555 18:53
     
     

    Hi Frank,

    Is it possible that my window is so different than yours because I have Microsoft SQL Server 2005 installed on my computer?  Help???

    Thanks,

    Bob.

  • 18 พฤษภาคม 2555 18:57
     
     

    Hi Frank,

    Is it possible that my window is so different than yours because I have Microsoft SQL Server 2005 installed on my computer?  Help???

    Thanks,

    Bob.


    Well, I don't think so but I'm out of my league on this one. There are some folks here that I know will know the answer, or can point you to something to lead you to the answer, but I'm stumped on it.

    Please call me Frank :)

  • 18 พฤษภาคม 2555 22:51
     
     

    Hi Frank,

    I just posted my questions under title " Creating the database from scratch" and I hope someone here will help me with this.

    Thanks,

    Bob.

  • 18 พฤษภาคม 2555 22:51
     
     

    Hi Frank,

    I just posted my questions under title " Creating the database from scratch" and I hope someone here will help me with this.

    Thanks,

    Bob.