|
I am getting error in the following code...
---------------------------------------------------------------------------------------
<br />
<br />
odbAdapter = New OleDbDataAdapter("select * from tblEmployeeAttendance", objConnection)<br />
<br />
ap.Fill(ds, "EmpAttendance")<br />
<br />
Dim i As Integer = ds.Tables(0).Rows.Count
---------------------------------------------------------------------------------------
When I add a watch on "ds.Tables(0).Rows" add check its Items property....
I see "In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user."
Following is the structure of tblEmployeeAttendance table in an MS Acceess database.
ID - AutoNumber
EmployeeCode - Text
AttendanceDate - date/Time
AttendanceCode - Text
AttendanceDescription - Text
AttendanceDescriptionDate - Date/Time
-------------------------------------------------
Do you have any idea about the cause of this error...?
Thanks,
Arun
“The woods are lovely, dark and deep. But I have promises to keep, and miles to go before I sleep.”
|
|
|
|
|
You have to supply the row index to view the data with in. In this case you would have to watch ds.Tables(0).Rows(0).ItemArray in order to see the first row in the table.
But if you have Visual Studio 2005 you can do a QuickWatch and click on the magnify glass icon to actually load the whole database into a grid to view the data...not available in VS2003 though.
Hope this helps.
|
|
|
|
|
Thanks for your help.
Now, using
Dim i As String = dsToupdate.Tables(0).Rows(0).Item(0)
returns correct value.
But how can I use it in looping through each row in the data set...
Currently my code looks like this...
For Each dr As DataRow In dsToupdate.Tables(0).Rows<br />
If (dsToupdate.Tables(0).Rows.Count > 0 And (Not (dr.Item("EAR_Employee_Code") Is Nothing))) Then<br />
<br />
dr.Item("EAR_Employee_Code") = strEmpCode<br />
dr.Item("EAR_Attendance_Date") = dtpAttendanceDate.Value<br />
dr.Item("EAR_Attendance_Code") = strIsPresent<br />
dr.Item("EAR_Attendance_Desc") = strDesc<br />
dr.Item("EAR_Attendance_DescDate") = strDescdate<br />
<br />
End If<br />
Next
------------------
can you please provide me a hint how to change the above code to access each item in each data row...?
I am using VS2005.
Thanks,
Arun
“The woods are lovely, dark and deep. But I have promises to keep, and miles to go before I sleep.”
|
|
|
|
|
I guess I really don't understand what you are asking. I think you are doing it correctly. You do not need the dsToupdate.Tables(0).Rows.Count > 0 check because the For Each statement will not run if the table is empty. But I don't know of any other way to access each column in the data row. It's easier to user the column names like you did here, than to use the indexes of the columns. Unless you are setting all of the items to the same number, in which case you can loop through the columns inside your row loop...by adding something like this:
For Each dc as DataColumn in dsToupdate.Tables(0).Columns<br />
dr.Item(dc.Name) = "VALUE"<br />
Next
Hope this helps.
|
|
|
|
|
Hi!
With the help of your first post I successfully solved the issue.
A 5 from my side.
Thanks a bunch...
Bye
“The woods are lovely, dark and deep. But I have promises to keep, and miles to go before I sleep.”
|
|
|
|
|
Ok, so I have a button that when pushed, it runs a batch of code.
My question is, is there a way to, when the button is pushed, put a progress bar to monitor when the batch of code is finished running and the progress it has made while it is running?
Any help at all is appreciated.
Thanks.
|
|
|
|
|
Yes. You should research the Background Worker object and the Pogress Bar control.
Here[^] is a list of articles to help you get started.
|
|
|
|
|
Hello,
I need to drag some graphics images across the screen, across other backgound items. Anyone have snippet or ideas of how to do that? I've looked at rubber-band lines, for instance, but didn't find anything good yet.
Seems maybe like
1. when the mouse goes down, erase the image and get a snapshot of the background screen
2. draw the image in its new place(s) as the mouse is moved
3. when the mouse is lifted, redraw the snapshot from (1) and the draw image in its final place.
Seems like there should be an easier way?
Thanks
|
|
|
|
|
What's easier than that ? This is still programming, we still need to write code. Any movable object, I would simply draw it in the paint event, and change the location and invalidate during mouse move if it's being moved.
You can use CreateGraphics to draw a dragged object if yuo like, but I don't see the benefit.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
i have developed an application to zip the file using shell32.dll file and natively zipped the file now i want to encrypt the file with password ie.,same as how we provide password to the zipped files
i want to do this programmatically can anyone please help me out in this regard it will be great help!!!
Thanking You in advance
nagashree
|
|
|
|
|
The shell does not support this, you'll need a third party library to do that.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Quote
The WinZip Command Line Support Add-On is a FREE add-on for users of WinZip Pro with a valid license. Before installing this add-on, please make sure you have WinZip Pro installed.
The WinZip Command Line Support Add-On provides a command line interface that gives you the power of WinZip without the usual WinZip graphical user interface. It allows you to use WinZip directly from the command prompt and from batch (.BAT) files and script languages, making it ideal for automating repetitive tasks. An extensive set of command line options gives you pinpoint control over WinZip's actions. And, in automated environments, end-users need not know anything about how to use WinZip.
Thats a wrap!
Autodev
|
|
|
|
|
If my application is Windows Form I just use App.StartUpPath,But if it is class library can i get path of library.
|
|
|
|
|
Hi,
you will need the Assembly class, get the assembly instance you are interested in
(maybe with GetExecutingAssembly), and look at one of its properties (probably Location).
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Thank you Luc Pattyn you help me again.
|
|
|
|
|
Hello,
I am trying to complete a small project in VB, but am having a problem figuring out how to handle a button click within the event of a current button click. The book I am using is not very descriptive in this case and I can't find any other examples with like code. I have most of the project complete, but I am stumped on the extra button click handling part of it. Most projects I have completed just gathered information from textboxes etc, but this is the first that asks for input from another button click and I can not find any examples. I need to have small button click converted into the numbers 1, 2, and 3 respectively so that when the button is clicked, the program will subtract that number from the total and then go back and decide whose turn it is.
The book I am using is: Visual Basic 2005 6th edition by David Schneider
Here is the project requirements:
Write a program that allows the user to challenge the computer to a game of pick-up-sticks. Here is how the game works. The user chooses the number of matchsticks (from 5-50) to place in a pile. Then, the computer chooses who will go first. At each turn, the contestant can remove one, two, or three matchsticks from the pile. The contestant who chooses the last matchstick loses.
The computer should make the user always select from a pile where the number of matchsticks has a remainder of 1 when divided by 4. For instance, if the user initially chooses a number of matchsticks that has a remainder of 1 when divided by 4, then the computer should have the user go first. Otherwise, the computer should go first and remove the proper number of matchsticks. (Note: The remainder when n is divided by 4 is (n Mod 4)) After writing the program, play a few games with the computer and observe that the computer always wins."
My Code So Far:
Public Class frmGame
Private Sub btnRules_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRules.Click
MsgBox("If you would like to play a game of Pick up Sticks, you must first choose a number of sticks from 5-50 to be placed into the pile, then when it is your turn you may select 1, 2, or 3 as the number of sticks to take from the pile. The contestant who chooses the last matchstick loses. Click Begin a New Game to get started.", 0, "Rules")
End Sub
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
Dim sticks As Double
Dim one As Double
Dim two As Double
Dim three As Double
GetInput(sticks, one, two, three)
DisplayStatus(sticks, one, two, three)
End Sub
' Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click
'Dim sticks As Double
' Dim one As Double
' Dim two As Double
' Dim three As Double
'CalculateSticksOne(sticks, one, two, three)
' DisplayStatus(sticks, one, two, three)
' End Sub
Sub GetInput(ByRef sticks As Double, ByRef one As Double, ByRef two As Double, ByRef three As Double)
'calculate which user goes first
sticks = InputBox("Please enter how many sticks the pile should begin with. Choose a number from 5-50.", "Choose number of Sticks")
End Sub
' Sub CalculateSticksOne(ByRef sticks As Double, ByRef one As Double, ByRef two As Double, ByRef three As Double)
' one = 1
' End Sub
Sub DisplayStatus(ByVal sticks As Double, ByVal one As Double, ByVal two As Double, ByVal three As Double)
Dim pile As Double
pile = CalculatePile(sticks, one, two, three)
If pile = MsgBox("It is your turn to choose.", 0, "Pick up Sticks") Then
pile = sticks
txtPile.Text = pile
Else
txtPile.Text = pile
End If
End Sub
Function CalculatePile(ByVal sticks As Double, ByVal one As Double, ByVal two As Double, ByVal three As Double)
Dim status As Double
If sticks Mod 4 = 1 Then
status = MsgBox("It is your turn to choose.", 0, "Pick up Sticks")
Else
status = sticks - 2
End If
Return status
End Function
End Class
-------------
If anyone has any suggestions on how to handle the three small button clicks within the main program click, please let me know! I can not locate this information in the text book and have not been able to find help anywhere else. I think once I can figure out how to code those button clicks, I should be able to be ok as I know I am missing the code where the computer wins, but can code that later. For reference, know that I am expected to utilize sub procedures and functions when appropriate in my programs at this point so I can not eliminate them.
If you would need my project.vb and project.design.vb to look at, please let me know!
Thank you so much in advance!
Erin0201
|
|
|
|
|
I think you mean that you want a member variable to store a number and that number changes when you click the button ? So it remembers it's last value and then changes on the click ?
Public Class frmGame
dim i as int = 0
Private Sub btnRules_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRules.Click
I don't do VB ( it's nasty as hell ), but I think this syntax is correct. Certainly, if you declare a variable outside of any method, it's a member and will be visible to all methods, and keep it's value between method calls.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I have been searching for a solution on using a custom cursor within a program I am writing. I would like to place a custom cursor (say PickBox.cur) in the resource folder that is located in the Solution Explorer and access it from the program by using the following code...
Me.cursor=My.Resources.Pickbox
When I try doing this, it gives me an error "Value of type '1-dimensional array of Byte' cannot be converted to 'System.Windows.Forms.Cursor'."
I can use a similar method as noted above to access icons in the resource folder, but for some reason it does not like working for cursors.
Could someone please help me out on solving this problem. I have searched the internet, and web sites, but have not found a solution that actually worked.
Any help would be greatly appreciated.
Thank you!
|
|
|
|
|
Do you need to cast it to System.Windows.Forms.Cursor before assigning it?
|
|
|
|
|
Thank you for the help, but not sure what you mean by "cast". sorry. I searched for help on this, and still nothing. Can you give me an example?
Thank you.
|
|
|
|
|
Do While MyReader.Read<br />
ComboBox97.Items.Add(MyReader.GetString("0"))<br />
Loop
their error in this statment
the error is "Specified cast is not valid".
please what is it mean and how i can cover from it
|
|
|
|
|
You might want to describe what you want this code to do, because it doesn't make a whole lot of sense right now.
It looks like you're trying to read a stream of characters, one by one, and adding each character to a combobox as a seperate item. Is this really what you want??
|
|
|
|
|
MyCmd.Connection = con<br />
MyCmd.CommandType = CommandType.Text<br />
MyCmd.CommandText = "SELECT SectionID FROM([Section]) WHERE (CourseID = '" & ComboBox96.Text & "')"<br />
MyReader = MyCmd.ExecuteReader<br />
Do While MyReader.Read<br />
ComboBox97.Items.Add(MyReader.GetString("0"))<br />
Loop<br />
<br />
MyReader.Close()
i am reading from database sectionid and i fill it to combbox
i do this with deferent data and it work but in this statement it give the error
can you help me
it dos not giv error in the fllowing code
g1 = ComboBox95.Text<br />
Dim MyCmd As New OleDbCommand<br />
Dim MyReader As OleDbDataReader<br />
con.Open()<br />
MyCmd.Connection = con<br />
MyCmd.CommandType = CommandType.Text<br />
MyCmd.CommandText = "select DISTINCT CourseID from Course where LevelNo=" & g1<br />
MyReader = MyCmd.ExecuteReader<br />
Do While MyReader.Read<br />
ComboBox96.Items.Add(MyReader.GetString("0"))<br />
Loop<br />
MyReader.Close()<br />
con.Close()
|
|
|
|
|
MyCmd.CommandText = "SELECT SectionID FROM([Section]) WHERE (CourseID = '" & ComboBox96.Text & "')"
change to:
MyCmd.CommandText = "SELECT SectionID FROM [Section] WHERE CourseID = '" & ComboBox96.Text & "'"
|
|
|
|
|
thinks but it dos not work
the same error "Specified cast is not valid"
the query i use it in other place and it work
i don't think the error from the query
|
|
|
|
|