|
-
Jun 15th, 2009, 05:15 AM
#1
Thread Starter
Fanatic Member
get maximum value of a dataset
Hello, I am looking for how to get the maximum value record on my dataset. I found this code
Code:
(maximumRecord = myDataset.compute("Max(columnName)", ""))
on google but this is not working with a dataset, it is suppose to work on a table, but I need to get the maximum value of a specific data that I put into a dataset.
-
Jun 15th, 2009, 05:19 AM
#2
Re: get maximum value of a dataset
DataSets don't have maximum values. In fact, they have no values at all. DataSets contains DataTables. It's the DataTables that contain the columns that describe the data and the rows that contain the data. You can't possibly have put any data directly into a DataSet because it's simply not possible. You have to have put the data into a DataTable, so just call Compute on that DataTable.
-
Jun 15th, 2009, 05:28 AM
#3
Thread Starter
Fanatic Member
Re: get maximum value of a dataset
well, I can't just call the whole table because I need to calculate the maximum value of a specific data, I'll show you what I got. I am trying to use the maximum value to make a primary key.
Code:
Dim maximumRecord As String
Private Sub Load_History()
Dim fontname As String = "Tahoma"
Dim fontsize As Integer = "8"
Dim fnt As New Font(fontname, fontsize, FontStyle.Regular)
Dim myCnt As Integer
Dim myStr As String
Dim myDataset As New DataSet
myStr = "select * from notes where Orderref='" + txtorderref.Text + "'"
Dim sqldaHistory As New SqlDataAdapter(myStr, nwindconn)
sqldaHistory.Fill(myDataset, "notes")
myCnt = myDataset.Tables(0).Rows.Count
'can't use noteCounter which works but would cause me errors if a row gets deleted, myDataset.Tables(0).Rows.Count method not suitable for PKs
'noteCounter = myDataset.Tables(0).Rows.Count
'maximumRecord = myDataset.compute("Max(noteref)", "")
Do While myCnt > 0
myCnt = myCnt - 1
Dim lblName As New Label
'name is not yet on notes table, to be copied from orders owner
lblName.Text = myDataset.Tables(0).Rows(0).Item("name")
lblName.Font = fnt
Dim lblEvent As New Label
lblEvent.Size = New Size(134, 17)
'event is on notes but most of the records are empty
lblEvent.Text = myDataset.Tables(0).Rows(0).Item("Event").ToString
lblEvent.Font = fnt
Dim lblNote As New Label
lblNote.Text = myDataset.Tables(0).Rows(0).Item("note")
lblNote.Size = New Size(1105, 39)
lblNote.Font = fnt
lblNote.AutoSize = True
pnlNewNote.Controls.Add(lblName)
pnlNewNote.Controls.Add(lblEvent)
pnlNewNote.Controls.Add(lblNote)
Loop
End Sub
So I want to get the maximum value from these records:
Code:
myStr = "select * from notes where Orderref='" + txtorderref.Text + "'"
-
Jun 15th, 2009, 05:41 AM
#4
Thread Starter
Fanatic Member
Re: get maximum value of a dataset
I just tried this but I got an error:
An expression of non-boolean type specified in a context where a condition is expected, near 'M0800176 '.
Code:
Dim db_command As New SqlCommand("select max(NoteRef) as max_NoteRef from notes where '" + txtorderref.Text + "'", nwindconn)
Label1.Text = db_command.ExecuteScalar()
-
Jun 19th, 2009, 04:05 AM
#5
Thread Starter
Fanatic Member
Re: get maximum value of a dataset
That's what I been looking for
Code:
maximumRecord = myDataset.Tables(0).Compute("Max(noteref)", "")
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|