Reputation: 43
I've just searched through vb.net examples on how to get the "SUM of a database", now I got this but how would I display this in textbox1 and textbox2?
But I don't know how to insert this to textbox.
Try
conn = New OleDbConnection(Get_Constring)
conn.Open()
cmd.Connection = conn
cmd.CommandType = CommandType.Text
sSQL=" Select userName,sum(quiz) as SumQuiz,sum(total) as Total From xxx where [username]='ad' And studentID='1111111'"
cmd.CommandText = sSQL
da.SelectCommand = cmd
Upvotes: 0
Views: 1428
Reputation: 4358
My VB is not that strong. You can try out OleDbDataReader
for reading the data into variables. Then assign the value of the variable to textbox1.Text
and textbox2.Text
Dim user As String
Dim sumQuiz As Integer
Dim total As Integer
Try
conn = New OleDbConnection(Get_Constring)
conn.Open()
cmd.Connection = conn
cmd.CommandType = CommandType.Text
sSQL=" Select userName,sum(quiz) as SumQuiz,sum(total) as Total From xxx where [username]='ad' And studentID='1111111'"
cmd.CommandText = sSQL
OleDbDataReader dr = cmd.ExecuteReader()
If dr.Read() Then
set user = Convert.ToString(dr["userName"])
set sumQuiz = Convert.ToInt32(dr["SumQuiz"])
set total = Convert.ToInt32(dr["Total"])
End If
Upvotes: 1