none
DataSet Problems RRS feed

  • Question

  • Hi,

    I'm using a dataset to store my information about students. I then want to either accept or decline students based on their postcode. However when I check whether my postcode is in my database, it says it isn't even when it is. This doesn't happen on all, just about 1 in 100, i know that the postcode does exsist becuase when it then trys to add it, it comes up with a constraint problem becuase the postcode is the primary key. Does anyone have any ideas on how to solve this?

    I am using if (Step.PostCode.FindByPostCode(postcode) == null) to check whether a value exsists in my table, would that be causeing the problems. I also have a gridview so i can see what is actually in my database and even i can see that a particular postcode which is returns as null is in the database.

    Any help would be greatly appreciated on this matter!

    Thanks

    Daniel
    Sunday, May 13, 2007 9:15 AM

All replies

  • Can you post the source of FindByPostCode method.
    I can gues what is the problem, like empty space problem, or invalid check in FindByPostCode method.
    Sunday, May 13, 2007 9:36 AM
  • Hi,

    Thanks for replying, FindByPostCode is a built in method of DataRowColletion.Find. I'm probably using it the wrong way, but it seems to work for everything else.

    Just a bit more info, i have one column in the database PostCode and a dataset which handles it all. This is how postcodes get added to the database:

    Code Snippet


                    step.PostCode.AddPostCodeRow(textBox1.Text);
                    postCodeTableAdapter.Insert(textBox1.Text);
                    postCodeTableAdapter.Update(stepDataSet.PostCode);


    Which seems to work fine, it just can't find them again (sometimes).

    Thanks

    Daniel
    Sunday, May 13, 2007 10:05 AM
  • Can you check the database, to see what is in the field for searched PostCode that makes you problem. For example if your table column is defined as char(5) and you insert "1111" and you search for it, you will not find it because in table field you will have "1111 ".
    Also if you work with SQL Server then open Profiler and check the sql statement, play with it in Query window and find out the reason of the problem.
    Sunday, May 13, 2007 10:43 AM
  • Hi,

    My column is actually defined as nvarchar(max), even though only every 2 characters are being stored in it. This problem is only happening with every 1/100 postcodes, for example if i have a postcode begining with RG, it will add that to the database, then it will automatically add every student whoes postcode begins with RG, however it doesn't want to do that all the time.

    May I ask what Profiler is? I've never used it, i am currently working with everything through Visual Studio and SQL Express.

    Thanks

    Daniel
    Sunday, May 13, 2007 11:45 AM
  • Profiler is a tool for whathing what is going on, on the SQL Server. You are using SQL Express and for that version Profiler is not working.
    If you are sure that insert is finished, that select statement for finding existing postcode is right, and you are working with SQL Express, you should first check that you are working on one database file. That is common problem when you work with SQL Express. About type of column, you know that there should be no comment, please change it.
    Sunday, May 13, 2007 2:23 PM
  • I don't think that it is a problem with SQL Express or the fact i may or maynot be working on different files because this problem only happens intermittenly. Only happens every 1 in 100 students. I have however noticed something else which could be a clue to this mystery, it doesn't happen if i add the postcode in the same adding process. For example if i add RG to the table and add all those students it will work fine, but then if i stop close and re-open the problem it won't find the postcode again (even though i can see it in my datagrid view).

     

    Thanks

     

    Daniel

    Monday, May 14, 2007 8:42 AM