how to detect end of row?

ss123

Member
Joined
Feb 25, 2006
Messages
14
Programming Experience
1-3
does anyone know how to detect the row in table is end of row and create a new key and record to it? Please advise. Thank you.
 
Ok, let me ask a few questions before I answer.

What are you doing that you need to detect the 'end of row'. Do you mean the last Row of a table? If so you would be checking the record position against the record count. If you want to add the next logical record, you would move to the last record , get It's KEY value, add 1 or something to it and add a new record.

Please rephrase your question and be a little more specific so we all can provide more accurate help.
 
insert new record

hi, actually i'm trying to insert the new record to the db, but the format for the key is string, so i wonder how to go to the last row and add 1 to it... Please advise. Thank you.
 
Ok, lets start with the easy part. To move to the last record of a dataset you need to move the position to the index of the last record. To get the index value you need to get the dataset's count and subtract 1. Indexes are zero based - the first record is index(0).
Simple code for moving the record pointer to the last record (accessing the last record) would be:
VB.NET:
Me.BindingContext(DataSet11, "TableName").Position = (Me.BindingContext(DataSet11, "TableName").Count - 1)
Now for adding to a string:
This depends on the format of the string. If it is just a number defined as a string you can define a string variable. Convert the string to an integer, add one and continue on you way.
VB.NET:
Dim YourString As String '= dataset key value
Dim testInt As Integer
testInt = Convert.ToInt32(YourString)
testInt += 1
new dataset key value = testInt.ToString
String are usually not that simple, though. If your string has som alpha or special characters mixed in you will need to 'parse' the string into something useable.
Some quick searches on 'Parse String' or the 'Trim' function should get you started in the right direction.

Use of try and/or if statements should be used to catch any errors.
VB.NET:
If IsNumeric(YourString) Then

End If
 
Back
Top