I do not want to bind the dataset to a repeater, I want to run if else statements according to whether rows exist in the dataset.
Is it possible to work with this dataset as such
in pseudocode
if (mydataset.rowexists where photoID = 1) = true
if (mydataset.rowexists where photoID = 2) = true
if (mydataset.rowexists where photoID = 3) = true
if (mydataset.rowexists where photoID = 4) = true
etc
If so is this an efficient way to work ? Is there alot of overhead?
Any tips, suggestions, or insight into this are greatly appreciated. I've been totally stuck on this for a couple days.
Thanks alot
mike123One way you could do it would be like that:
For X as integer = 1 To 8
if mydataset.mydatatable.select("photoID = " & X).lenght > 0 Then
'There is at least one row with a photoID of X
Else
'There is no row with a photoID of X
End If
Next
thanks alot for the quick response psychopif
ultimately what I want to do is bind the row of photoid1 to label1 if it exists, if it doesnt i bind alternate text
would u just put a select case inside the if / else statement?
Oh and also, there will only be one row per photoID max
thanks alot for your help
mike123
So you're saying that you will always have 8 labels and, depending on if a row exist in the table, you'll ouput appropriate text for each label ?
Even if there is only one row matching the Select statement, you will still get an array.
Yes psychopif, thats exactly whats gonna happen.
I tried your code, but I have never used a datatable / dataview.
I get the error
"mydatatable is not a member of system.data.dataset"
Could you please provide the whole piece of code? (Seems like something is missing, delcaring the datatable etc??) (vb preferred but C# is still very helpful) I cant seem to find a decent article anywhere.
I woudl really appreicate this.
Thanks alot
mike123
I was wrong, I don't think you're working with a typed DataSet so...
Try myDataSet.Tables("TheNameOfYourTable").Select instead
If that still don't work, please provide me with you code where you create your DataSet
Dim photo As 123.photo = New 123.photo()
Dim myDataSetExtraPics As DataSet = photo.select_ExtraPhotos(productID)
Dim x As Integer
For x = 1 To 8
If myDataSetExtraPics.Tables("select").Select("photoID = " & x).Length > 0 Then
'There is at least one row with a photoID of X
'this value below I want to set to the corresponding "CounterID" where the photoID is found
'Dim UniquePhoto & cstr(x) As String = CStr(myDataSetExtraPics.Tables(0).Rows(0).Item("counterID"))
Else
'There is no row with a photoID of X
End If
Next
myDataSetExtraPics.Dispose()
myDataSetExtraPics = Nothing
photo.Dispose()
photo = Nothing
I don't think we are heading in the right direction.
What I would do is make the photoID the PrimaryKey of your table so you could use the DataTable.Rows.Find() Method. That would make your code a lot cleaner and much more robust. Then you could just to something like this:
If Not myDataSetExtraPics.Tables("TheTableName").Rows.Find(1) Is Nothing Then
Label1.Text = "There is an image with a photoID of 1"
Else
Label1.Text = "There is no image with a photoID of 1"
End IfI would then repeat this code for each of the 8 Label.
Again that would work as long as you have only 8 Label. Otherwise, I would strongly suggest a Repeater.
Thanks again psychopif,
This seems more in the right direction. Are you talking about making the photoID the primary key of my datatable? If so how can I do this, or can you point me to a good article I cant seem to find anything =\ Or my SQL table in my sqlserver database?
My SQL server table is layed out like this
1counterIDint40
0photoIDtinyint10
0productIDint40
0photoDatesmalldatetime40
CounterID = identity column, also used to randomize the filename
photoID = value of 1-8, each productID may have up to 8 rows, no duplicates
productID = product value
photoDate = date entered
Also this code that your provide is exactly what I need, but I need to go one step further and also bind another value that is in the selected row
If Not myDataSetExtraPics.Tables("TheTableName").Rows.Find(1) Is Nothing Then
Label1.Text = "There is an image with photoID of 1 and its security number is" &
'pseudocode
counterID [ WHERE myDataSetExtraPics.Tables("TheTableName").Rows.Find(1) ]
Else
Label1.Text = "There is no image with a photoID of 1"
End If
Hopefully this clears a few things up and Im not confusing the situation more. Any tips, suggestions or insight would be greatly appreciated.
Thanks alot for your help
Mike123
That would'nt work if your identity is the counterID, that's what should be the primary key.
Maybe that would be better
Dim aRow as DataRow
Dim photo As 123.photo = New 123.photo()
Dim myDataSetExtraPics As DataSet = photo.select_ExtraPhotos(productID)'Repeat this part for each label
aRow = myDataSetExtraPics.Tables("select").Select("photoID = 1")(0)
If Not aRow Is Nothing Then
Label1.Text = "There is an image with photoID of 1 and its security number is" & aRow("counterID")
Else
Label1.Text = "There is no image with a photoID of 1"
End If
Please contact me by mail at psychopif@.hotmail.com if you want further help. I'll be out of office for the rest of the week. If you could send me the code you have so far, It will be easier for me to understand.
0 comments:
Post a Comment