none
datarows.find error RRS feed

  • Question

  • this is the code i have for to find the datarow.

     

    Code Snippet

    DataRow letsFind;

    letsFind = this.barCodeNumbersDataSet.BarCodeNumbers.Rows.Find(numBarCode);

     

    numBarCode is an eleven digit number, but is a string.  The primary key column called BarCode in my database is also of the string type, and it holds all the available BarCodes.  These two lines of code compile fine, but when the program gets to the second line during runtime, it pops up an error message that says, "Value was either too large or too small for an Int32".  I don't know what this message means.  What Int32 are they talking about because all I thought I was working with are strings.  Does the primary key have to be an Integer?  Let me know if you have any ideas. Thanks.

    Tuesday, July 24, 2007 9:48 PM

Answers

  • I think I tried this before, but I gave it a shot again. I'm not sure I'm getting the paramaters right for this method.

     

    BindingSource.Find( string propertyName, Obj key);

     

    What is the string propertyName?  Is that the name of the column you are searching in?  And is the Object key the value you want to find?  And is the index it retrieves the row index?  If you answer these questions I think my problem will be solved because this looks like exactly what I need.

     

    Thanks.

    Thursday, July 26, 2007 2:43 PM
  •  

    Ok, I figured it out.  The correct line of code is.

     

    int dataValue = this.dataset.datatable[(row index)].(column name);

     

    Thanks for all your help.  I think that is all of the help I need as of right now.  Take care everyone.

    Thursday, July 26, 2007 7:41 PM

All replies

  • If you are using a typed-dataset, could you go into the dataset's raw XML and paste it in a reply?  It'll be easier for us to give you some ideas in regard to where to start looking.
    Tuesday, July 24, 2007 11:33 PM
  • What is the type of numBarCode variable? If it is declared as integer, not string, it is quite possible you will get overflow. If column is string, then you should use string type of variable as well to search data.
    Wednesday, July 25, 2007 10:40 AM
    Moderator
  •  ARK88 wrote:
    If you are using a typed-dataset, could you go into the dataset's raw XML and paste it in a reply?  It'll be easier for us to give you some ideas in regard to where to start looking.

     

    Not sure if it is typed or untyped.  I forgot the difference between the two.  All I did was set that datasource of the dataviewgrid to a database and it provided me with a tableadapter and bindingsource.  My program works by bringing in a barcode number from a scanner.  Then I reference the number to a database and show a bunch of information on the form about it.

     

    Now I am looking for a way to search the database using the barcode again, but without using the datagridview.  My gameplan was to find the index of the row that matches that barcode.  I only want to put information from one column into a variable, and it is always the same one, so the column index is going to be static.  If someone knows of an easier way to go about this, I am up for suggestions.

     

    Bottomline, I am trying to do what the datagridview query does, but by using code only (no graphical representions) and instead of showing the whole row associated with the given barcode number, I just want to save the information from one column (from that row) into a variable.

     

    Hope I didn't confuse you as much as I confused myself. 

    Wednesday, July 25, 2007 3:44 PM
  •  VMazur wrote:
    What is the type of numBarCode variable? If it is declared as integer, not string, it is quite possible you will get overflow. If column is string, then you should use string type of variable as well to search data.

     

    The numBarCode variable is a string and the column in the access database is set to "Text", which I assume is also a string.  That's why I don't understand where the Int32 error is coming from since they are both strings.

    Wednesday, July 25, 2007 3:47 PM
  • I don't want to side-track us too much from the path we are on, but I just want to throw this out and see if you've tried it yet...  BindingSource has a "Find" method on it, that you provide with the property/column you want to search on and the value you are searching for... the result of that method is the index of the item that matches that criteria.  Is that something that is feasible for you to try?  It also makes sense in regard to the fact that the BindingSource is what is attached to your grid, so it is technically more accurate (in my opinion) because you can filter on the BindingSource, so referencing the real dataset might give you the wrong index value (because the real dataset might not have been filtered at all).  Enough babbling, is that worth a shot?
    Wednesday, July 25, 2007 9:26 PM
  • I think I tried this before, but I gave it a shot again. I'm not sure I'm getting the paramaters right for this method.

     

    BindingSource.Find( string propertyName, Obj key);

     

    What is the string propertyName?  Is that the name of the column you are searching in?  And is the Object key the value you want to find?  And is the index it retrieves the row index?  If you answer these questions I think my problem will be solved because this looks like exactly what I need.

     

    Thanks.

    Thursday, July 26, 2007 2:43 PM
  • I didn't actually try it, but I believe everything you said sounds correct.  If you run into problems with it, let us know and we'll try to help figure it out.

     

    Thursday, July 26, 2007 3:30 PM
  • Alright I got it to work.  I now know the column index number and the row index number of the value I want out of the database.  Any ideas on how to retrieve that value?  I looked through a lot of the methods but couldn't find one that worked as of yet.  The kind of things I was looking for was something like:

     

    dataset.columnID[3].Value

     

    So I'm looking for some variation of that where you can get the value from a specific cell if you have the column and row index numbers.  Thanks for all the help so far.

    Thursday, July 26, 2007 7:19 PM
  •  

    Ok, I figured it out.  The correct line of code is.

     

    int dataValue = this.dataset.datatable[(row index)].(column name);

     

    Thanks for all your help.  I think that is all of the help I need as of right now.  Take care everyone.

    Thursday, July 26, 2007 7:41 PM