I'm back again as I'm waiting for the coffee to kick in and have another question that seems to be not causing my brain cells to fire correctly.
I've set the following code to determine the line numbers of all rows returned from the procedure loop.
linenum = 0
Do While (rsData.Read())
linenum = linenum + 1
loop
Now I'm trying to code a button that will move users to different sections depending on the linenumber returned.
So if there's only one linenum with a value of 1, they get a button to 'Apply'.
If the total linenum values are greater than 1, they get a button to 'select apply date'.
Now again I'm having a brain fart and can't think of the logic if theres a linenum of 1+ how to determine the button should be displayed. It needs to include the value of 1 as well as there are more than one linenums so the button should display the 'select apply button'.
Any ideas?
Thanks!
I think you'll have better luck populating a DataTable and using the row indexes, or returning the row number from the stored procedure.
SELECT ROW_NUMBER() OVER(ORDER BY SalesYTD DESC) AS Row, FirstName, LastName, ROUND(SalesYTD,2,1) AS YTD
FROM Sales.vSalesPerson
WHERE TerritoryName IS NOT NULL AND SalesYTD <> 0
It looks like you're using a SqlDataReader currently, so it shouldn't be too difficult to adjust so it returns a DataTable instead:
DataTable table = new DataTable();
using (SqlDataAdapter adap = new SqlDataAdapter(cmd))
{
adap.Fill(table);
}
Not clear what you're trying to accomplish, but to directly answer your question:
if linenum = 0 then
mybutton.visible = false
else if linenum = 1 then
mybutton.visible = true
mybutton.text = "Apply"
else
mybutton.visible=true
mybutton.text = "Apply select"
end if
But I would think that if linenum > 1, someplace you also have to giv the user the list of things to select from, and a way to select one of them. Like build a dropdown box or something.
Related
I am currently trying to create a number that increases per entry and group in my table via a form.
The form is rather simple it utilizes a ComboBox to select the group from a different table. The generated number should start at 1 and increase for every new entry separately for each selected group.
Code:
My code attempts to create the number BeforeUpdate by searching for the DMax() of the variable for the group selected via ComboBox. Unfortunately, in this current state, the code does not increment the variable called Nummer but it does not throw an Error either.
Private Sub Nummer_BeforeUpdate(Cancel As Integer)
Nummer = Nz(DMax("[Nummer]", "Bau-Tagesbericht", "[Baustelle] = Kombinationsfeld354.Value")) + 1
End Sub
Variables:
Group: Baustelle
Variable that should be incremented: Nummer
Name of the Comobox: Kombinationsfeld354
I appreciate any kind of help, thank you!
You need to concatenate the variable - and set 0 (zero) for Null:
Nummer = Nz(DMax("[Nummer]", "Bau-Tagesbericht", "[Baustelle] = " & Kombinationsfeld354.Value & ""), 0) + 1
If text value, use single quotes:
Nummer = Nz(DMax("[Nummer]", "Bau-Tagesbericht", "[Baustelle] = '" & Kombinationsfeld354.Value & "'"), 0) + 1
Alright, maybe I'm missing something simple but I can not get an if statement inside a for loop to color a datagridview row based on a cell's value. Maybe you guys can see something I can't.
Here is my SQL code:
SELECT
Part,
CASE
WHEN missing = 1 OR secondmissing = 1
THEN '1'
WHEN missing IS NULL AND secondMissing IS NULL
THEN '0'
END AS 'missing'
FROM
TableA
This query returns a list of part numbers and if they have been marked as missing or not and appears to run fine. In my Winforms application, I have a For loop to check the datagridview loaded with the SQL query above to color any rows yellow that have the missing marked as 1. However nothing I seem to try work for catching line items marked as 1.
Here is my VB code:
For x as integer = 0 to DataGridView1.rows.count - 1
With Datagridview1.rows(x)
if .cells(1).value.tostring = "1" then *
.DefaultCellStyle.Backcolor = Color.Yellow
else
.DefaultCellStyle.BackColor = Color.White
End If
End With
Next
Notice in the for loop I marked a line with an *. Here are all the things I have tried here.
if .cells("missing").value = True Then
if .cells(1).value.tostring = "1" Then
if CInt(.cells(1).value) = 1 Then
if CInt(.cells(1).value.tostring) = 1 Then
None of the above options seem to work. If I try and use the column name "missing" instead of the column integer of 1 it completely misses the code.
Any help would be great.
EDIT:
I guess I should note the SQL columns datatypes: Part is NVARCHAR(25) and both missing and secondmissing are BIT.
I'm working with the following bit of code in VisualBasic.NET. It's essentially supposed to be pulling a row ID from the table with specific conditions in mind. However, I would like to set up a failsafe of getting around those conditions if need be.
I'm trying to write an If statement to compare the Item(0) against but this bit of code seems to trigger no matter what. How can I compare to see if the Query being written as QuestionConnectionQuery is actually returning rows?
For i As Integer = 1 To intNoOfQuestions
'TODO: If there are no valid questions, pull up any of them that meets the difficulty requirement....
' Go into the Database and retrieve a question that hasn't been selected in the last seven days.
Dim QuestionConnectionQuery As New OleDb.OleDbCommand("SELECT TOP 1 Questions.QuestionID, Questions.QuestionCategory & ' : ' & Questions.QuestionSubCategory AS Category FROM Questions WHERE (((Questions.QuestionDifficulty)=[?])) OR (((Questions.LastDateRevealed) Is Null)) OR ((Questions.LastDateRevealed)>=DateAdd('d',-7,Now())) ORDER BY Rnd(QuestionID);", QuestionConnection)
QuestionConnectionQuery.Parameters.AddWithValue("?", intQuestionDifficulty(i - 1).ToString)
Dim QuestionDataAdapter As New OleDb.OleDbDataAdapter(QuestionConnectionQuery)
Dim QuestionDataSet As New DataSet
QuestionDataAdapter.Fill(QuestionDataSet, "Questions")
' If the result is not null... add it to the array.
If IsNothing(QuestionDataSet.Tables("Questions").Rows(0).Item(0)) Then
' Add that to the intQuestArray() array
intQuestArray(i - 1) = QuestionDataSet.Tables("Questions").Rows(0).Item(0)
Else
MessageBox.Show("ERROR: Not enough questions.")
QuestionDataAdapter.Fill(QuestionDataSet, "Questions")
End If
' Update the database by adding today's date to the "LastDateRevealed" column of the table.
Dim QuestionUpdateQuery As New OleDb.OleDbCommand("UPDATE Questions SET LastDateRevealed=NOW() WHERE QuestionID = [?]", QuestionConnection)
QuestionUpdateQuery.Parameters.AddWithValue("?", QuestionDataSet.Tables("Questions").Rows(0).Item(0).ToString)
QuestionUpdateQuery.ExecuteNonQuery()
Next
If IsDBNull(QuestionDataSet.Tables("Questions").Rows(0).Item(0)) Then
https://msdn.microsoft.com/en-us/library/tckcces5(v=vs.90).aspx
I'm creating a Voting System. so it's like this every time A Button1 is pressed + 1 or it will increase the vote in the Access database. I can't find anything in Google.
trx = "update [Table1] SET [Vote] = Vote + 1, (WHERE ID = 1)"
Don't include a comma before the WHERE clause. Also you don't need to put the WHERE clause inside parentheses.
Test this as a new query in the Access query designer.
update [Table1] SET [Vote] = Vote + 1 WHERE ID = 1
Fine tune as needed. And once you have it working in the query designer, adapt your VBA code to use that working statement.
Remove comma before Where and brackets around where clause
trx = "update [Table1] SET [Vote] = Vote + 1 WHERE ID = 1"
I am using vb.net in visual studio to query my invoices.
i get a list of invoice of interest, and as i iterate through the list, i see the for each invoice i have, the invoice.ORInvoiceLineRetList is nothing.
here is a snippet of code, although i think i am doing everything right?
resp = SessMgr.DoRequests(msgReq)
resplist = resp.ResponseList
curResp = resplist.GetAt(0)
If curResp.StatusCode = 0 Then
Dim invoiceList As IInvoiceRetList = curResp.Detail
Dim curInvoice As IInvoiceRet
Dim i As Integer
For i = 0 To invoiceList.Count - 1
curInvoice = invoiceList.GetAt(i)
if i breakpoint right after the last line, i see curInvoice, and its data (e.g. refnumber), but i need to get to the line items.
can someone help?
Thanks,
Jerry
If your IInvoiceQuery is called invoiceQuery, add this (just replace invoice query with your IInvoiceQuery objects name if it's called something else)
invoiceQuery.IncludeLineItems.SetValue(True)
before this
resp = SessMgr.DoRequests(msgReq)
and that should fix your problem