|
This is how I fixed with help from a post on an another site. I do have one question though. If I comment out the first db connection - ConnDB() I get an error. Why does it need two connection to work? It makes a connection in the using command. I had setup a data table from a class I wrote to make a connection and set it up so I declare Private Access As New DBControl at the top and I can add parameters and do my additions and edits that way. I didn't know how to make that work with the existing connection to the Access DBControl so I just did another connection. Not the best but I am a beginner and don't know how to do things with more efficiency yet.
Private Sub tbStudentID2_TextChanged(sender As Object, e As EventArgs) Handles tbStudentID2.TextChanged
mySql = "SELECT DateDiff('d', [DateofRank], [currentDate]) FROM StudentData"
ConnDB()
Dim studentID As Integer
If Not Integer.TryParse(tbStudentID2.Text, studentID) Then
tbDays.Text = String.Empty
Else
Using command As New OleDbCommand("SELECT DateDiff('d', [DateofRank], [currentDate]) FROM StudentData WHERE StudentID = @StudentID", myConnection)
command.Parameters.AddWithValue("@StudentID", studentID)
ConnDB()
Dim days As Object = command.ExecuteScalar()
tbDays.Text = If(Convert.IsDBNull(days), String.Empty, Convert.ToString(days))
End Using
Access.AddParam("@TIG", tbDays.Text)
Access.AddParam("@SID", tbStudentID2.Text)
Access.ExecQuery("UPDATE StudentData " &
"SET TimeinGrade=@TIG " &
"WHERE StudentID=@SID")
If NoErrors(True) = False Then Exit Sub
End If
End Sub
|
|
|
|
|
I want to fill all the entries in a column with the current date so that I can compare it to a DateofTest column and determine how many days since the last test. I think I can figure out the number of days but I can't figure out how to fill the column with the current date.
Private Sub Reports_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
mySql = "Update Studentdata, SET currentDate = Date()"
ConnDB()
myCommand = New OleDbCommand(mySql, myConnection)
End Sub
|
|
|
|
|
Remove the comma.
UPDATE StudentData SET currentDate = DATE()"
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
No luck. I don't get an error it just doesn't do anything to the column.
|
|
|
|
|
As Richard pointed out, if you have shown all of your code you are never actually executing it.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
You forgot to execute the SQL command.
|
|
|
|
|
doesn't this execute the command? myCommand = New OleDbCommand(mySql, myConnection)
|
|
|
|
|
No, it just creates a OldDbCommand object. You actually have to tell it to execute using one of the Execute... methods.
|
|
|
|
|
That did the trick. I added mycommand.ExecuteNonQuery() and it worked perfect.
|
|
|
|
|
How to create new DateTime of months, going back 12 months
I'm writing some reports, that need dynamic months. Months going back a year, 12 Months from the current month.
So like today is Feb 17, 2020
Feb 1, 2020 to Feb 17, 2020
Jan 1, 2020 to Jan 31, 2020
Dec 1, 2019 to Dec 31, 2019
Nov 1, 2019 to Nov 30, 2019
etc
I tried this, M2 would be Jan 1, 2020, M3 would be Dec 1, 2019.
but it crashes on the M3, because the year rolls back to 2019. I get why it crashed.
Dim M2 = New DateTime(Now.Year, Now.Month -1, 1)
Dim M3 = New DateTime(Now.Year, Now.Month -2, 1)
Dim M4 = New DateTime(Now.Year, Now.Month -3, 1)
Dim M5 = New DateTime(Now.Year, Now.Month -4, 1)
Dim M6 = New DateTime(Now.Year, Now.Month -5, 1)
Dim M7 = New DateTime(Now.Year, Now.Month -6, 1)
Dim M8 = New DateTime(Now.Year, Now.Month -7, 1)
Dim M9 = New DateTime(Now.Year, Now.Month -8, 1)
Dim M10 = New DateTime(Now.Year, Now.Month -9, 1)
Dim M11 = New DateTime(Now.Year, Now.Month -10, 1)
Dim M12 = New DateTime(Now.Year, Now.Month -11, 1)
Then I'm curious on say Feb, if I create a stop date of say
Dim sM2 = New DateTime(Now.Year, Now.Month - 1, 31) since Feb has 28 or 29 days.
I suspect it will crash, haven't tried it yet.
Basically, these dates will be injected into a Linq group operation.
Well I guess I could write a function to calculate this, and pass months back and return a date with time of midnight.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Call the functions
Dim M9 = AmCommon.MakeMonthStartDate(-8)
Dim M10 = AmCommon.MakeMonthStartDate(-9)
Dim M11 = AmCommon.MakeMonthStartDate(-10)
Dim M12 = AmCommon.MakeMonthStartDate(-11)
Dim sM2 = AmCommon.MakeMonthStopDate(-1)
Dim sM3 = AmCommon.MakeMonthStopDate(-2)
Dim sM4 = AmCommon.MakeMonthStopDate(-3)
Dim sM5 = AmCommon.MakeMonthStopDate(-4)
Functions
Public Shared Function MakeMonthStartDate(byVal monthsBack as Integer) As DateTime
Dim month = DateTime.Now().AddMonths(monthsBack)
Dim fd = FirstDayOfMonth(month)
Return New DateTime(month.Year, month.Month, fd.Day, 0, 0, 0)
End Function
Public Shared Function MakeMonthStopDate(byVal monthsBack as Integer) As DateTime
Dim month = DateTime.Now().AddMonths(monthsBack)
Dim ld = LastDayOfMonth(month)
Return New DateTime(month.Year, month.Month, ld.Day, 23, 59, 59)
End Function
Public Shared Function FirstDayOfMonth(ByVal sourceDate As DateTime) As DateTime
Return New DateTime(sourceDate.Year, sourceDate.Month, 1)
End Function
Public Shared Function LastDayOfMonth(ByVal sourceDate As DateTime) As DateTime
Dim daysInMonth = DateTime.DaysInMonth(sourceDate.Year, sourceDate.Month)
Return New DateTime(sourceDate.Year, sourceDate.Month, daysInMonth)
End Function
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
|
That's funny Richard, so simple ..
I needed date blocks in months, probably a better way of expressing what I wanted.
Then I can take sales amount within the month blocks and put them in a report data set column
Sort of like ... This is a concept and not code...
FMTD_0 = SUM(FShipdate) >= Feb 1, 2020 And <= Feb 29, 2020
FMTD_1 = SUM(FShipdate) >= Jan 1, 2020 And <= Jan 31, 2020
FMTD_2 = SUM(FShipdate) >= Dec 1, 2019 And <= Dec 31, 2019
FMTD_3 = SUM(FShipdate) >= Nov 1, 2019 And <= Nov 30, 2019
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
So range 1 would be M1 to Today ; range 2 would be M2 to M1.AddDays(-1) ; etc.
Although it might be simpler to tweak the end condition slightly:
- >= 2020/02/01 And < 2020/03/01
- >= 2020/01/01 And < 2020/02/01
- >= 2019/12/01 And < 2020/01/01
- etc.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
HOW TO CREATE RDLC REPORT AND CALL IN VS 2013
|
|
|
|
|
|
Hi experts
Pls someone help me. I need retrieve data from listview to textbox, comboBox, Option Button and etc. Thanks a lot
|
|
|
|
|
What exactly is the problem?
|
|
|
|
|
Problem is. I need retrieve data in listview when I selected item in listview then transfer the data in textbox.
Example
I click the lastname in listview the show the clicked item in textbox
|
|
|
|
|
Use the click event and identify the selected item in the list box
get the text property of the selected item into a variable
update the text property of the textbox with the text from the variable.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
DataGrid with different controls
to excel with cell color in vb.net
I have already tried this code below like this:
Export ASP.NET DataGrid to Excel[^]
But I got some errors below like following these
1.Conversion from type 'ListItem' to type 'String' is not valid.
2.The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
|
|
|
|
|
Maybe with some code we can see whats wrong.
anyway: listitem and string are not the same type. listitem.text may help.
Jan
|
|
|
|
|
I have a weird situation where (randomly) a previous Cell value is read by the Excel VBA code.
eg: Cell 1A had a value = Y. It was updated to N. However a subsequent VBA code read the cell value as Y
It has been hard to troubleshoot as this was a random occurrence. I was lucky to catch one today, and upon stepping through the code (using F8) discovered that the correct current value was read during debug!. Re-run the macro without debug mode and the correct value was read.
Its very confusing and I cannot think of anything but an Excel bug.
Have you encountered this issue at all and if so what solution/s have you applied.
Thanks in advance.
|
|
|
|
|
With the amount of people that have been using Excel, it is very unlikely that there's a bug that's that basic. Also, the computer doesn't do stuff "randomly"; that's simply our way of describing stuff when we can't see the pattern.
Is there timing involved in your code? Can you reproduce the error?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Male sure you are reading the same value IE CurrentValue, excel has the ability to roll back changes and you may be reading from the wrong/different property.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|