|
you just need to use the openfilediag component and set a condition to test the file if it is the file extension you need or not. and display them is ok.
|
|
|
|
|
Hi I use this code and want to add id and avtor to combobox but display the field "avtor", when I select some from combobox I want to get "id"
Private Sub avtori()
Dim selectdata As String
selectdata = "SELECT id, avtor FROM avtor"
Dim strConn As String
Dim reader As OleDbDataReader
'Низ за връзка с БД
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strAcessFilePath1 & ";Jet OLEDB:Database Password=;"
OleDbConnection2 = New OleDbConnection(strConn)
OleDbConnection2.Open() 'Отваряне на връзка с БД
OleDbCommand2 = New OleDbCommand(selectdata, OleDbConnection2)
reader = OleDbCommand2.ExecuteReader()
'Цикъл за извличане на всички автори и тяхното добавя към комбинирина списъчна кутия
Dim i As Integer
While reader.Read()
ComboBox1.Items.Add(reader("avtor"))
End While
reader.Close()
OleDbCommand2.Dispose()
OleDbConnection2.Close()
End Sub
modified on Saturday, February 5, 2011 2:15 PM
|
|
|
|
|
Instead of going through a datareader and adding each item to the combobox, fill a datatable with the data, then bind the combobox to it using its DataSource property. Then set the combos DisplayMember (what the user sees in the list) and the ValueMember (what is returned by the combo) properties to the column names in the datatable.
|
|
|
|
|
I have the following sub routine
Private Sub Exceptionquery()
Dim connection As System.Data.SqlClient.SqlConnection
Dim connectionString As String = "Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx"
Dim _sql As String = "SELECT [Exceptions].Employeenumber,[Exceptions].exceptiondate, [Exceptions].starttime, [exceptions].endtime, [Exceptions].code, datediff(minute, starttime, endtime) as duration INTO scratchpad3 " + _
"FROM [Exceptions]" + _
"where [Exceptions].exceptiondate between @payperiodstartdate and payperiodenddate" + _
"GROUP BY [Exceptions].Employeenumber, [Exceptions].Exceptiondate, [Exceptions].starttime, [exceptions].endtime," + _
"[Exceptions].code, [Exceptions].exceptiondate"
connection = New SqlConnection(connectionString)
connection.Open()
Dim _CMD As SqlCommand = New SqlCommand(_sql, connection)
_CMD.Parameters.AddWithValue("@payperiodstartdate", payperiodstartdate)
_CMD.Parameters.AddWithValue("@payperiodenddate", payperiodenddate)
Try
connection.Close()
Catch ex As Exception
connection.Close()
End Try
End Sub
Private Sub exceptionsButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exceptionsButton.Click
Exceptionquery()
Dim connection As System.Data.SqlClient.SqlConnection
Dim adapter As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter
Dim connectionString As String = "Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx"
Dim ds As New DataSet
Dim _sql As String = "SELECT * from scratchpad3"
connection = New SqlConnection(connectionString)
connection.Open()
Dim _CMD As SqlCommand = New SqlCommand(_sql, connection)
_CMD.Parameters.AddWithValue("@payperiodstartdate", payperiodstartdate)
_CMD.Parameters.AddWithValue("@payperiodenddate", payperiodenddate)
adapter.SelectCommand = _CMD
Try
adapter.Fill(ds)
If ds Is Nothing OrElse ds.Tables.Count = 0 OrElse ds.Tables(0).Rows.Count = 0 Then
MessageBox.Show("There was no data for this time period. Press Ok to continue", "No Data")
connection.Close()
Exceptions.saveButton.Enabled = False
Exceptions.Hide()
Exceptions.Show()
Else
connection.Close()
Exceptions.Show()
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
connection.Close()
End Try
End Sub
and when I run my code, my subroutine is not being fired off. I know that because I would have a scratchpad3 in my sql database. I know that I'm probably missing something simple, but can anyone tell me what I may be missing?
Thank you
Doug
|
|
|
|
|
At a quick glance you do not execute the command.
Also there's something peculiar about your try block. You catch an exception if it fail on closing the connection, then try to close again. Thus raising another exception?
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
David,
Thank you for pointing that out to me. I changed the code:
Private Sub Exceptionquery()
Dim connection As System.Data.SqlClient.SqlConnection
Dim connectionString As String = "Initial Catalog=mdr;Data Sourcexxxxx;uid=xxxxx;password=xxxxx"
Dim _sql As String = "SELECT [Exceptions].Employeenumber,[Exceptions].exceptiondate, [Exceptions].starttime, [exceptions].endtime, [Exceptions].code, datediff(minute, starttime, endtime) as duration INTO scratchpad3 " + _
"FROM [Exceptions]" + _
"where [Exceptions].exceptiondate between @payperiodstartdate and payperiodenddate" + _
"GROUP BY [Exceptions].Employeenumber, [Exceptions].Exceptiondate, [Exceptions].starttime, [exceptions].endtime," + _
"[Exceptions].code, [Exceptions].exceptiondate"
connection = New SqlConnection(connectionString)
connection.Open()
Dim _CMD As SqlCommand = New SqlCommand(_sql, connection)
_CMD.Parameters.AddWithValue("@payperiodstartdate", payperiodstartdate)
_CMD.Parameters.AddWithValue("@payperiodenddate", payperiodenddate)
connection.Close()
End Sub
and I thought by using this command in my next sub
Exceptionquery()
that I was calling that subroutine.
|
|
|
|
|
Double-click on the "exceptionsButton" in the designer to make sure that it takes you to the specified procedure... VS may have mapped it differently.
|
|
|
|
|
Chandra,
I double checked it and the mapping is correct.
|
|
|
|
|
You are calling the routine but the routine does not execute the SqlCommand.
It just sets it up and provides values for the parameters.
You need and _CMD.ExecuteNonQuery.
BTW using _CMD as a variable name is a bit strange in VB - smacks of C++ with a mix of _ for class level variables and all upper case for constants. But that's a matter of taste.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
PS Meant to say you could wrap the connection stuff in a try...finally...end try block with the close in the finally part. Note no catch - if an exception occurs it will be thrown but the close will still be done.
VB also has the using...end using construct to do this automatically so you don't need the close.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
David,
I have now added this to my code:
_CMD.ExecuteNonQuery()
and I get the error: Incorrect Syntax near the keyword BY.
|
|
|
|
|
So your SQL statement is wrong.
There is a payperiodenddate with a @ missing.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Luc,
Thank you for noticing that. I have added that and now get the error:
'Must declare the variable for @payperiodenddateGROUP'
|
|
|
|
|
another obvious mistake. Check your SQL statement once more. The error message is very clear. Build up some confidence, and use this site for the hard stuff.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Luc,
I've verified that the sql query works and that the variables are being both declared and passed to my sub.
|
|
|
|
|
Look at the SQL - it seems to me there are missing spaces before keywords.
As antip always make sure there is one e.g.instead of "GROUP...." type " GROUP..."
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
hi all, im trying to register a ocx control tabctl32 on a windows 7 machines to run vb6.
if i run this command regsvr32 command, it finishes succesfully but if i go on a tab its still returnig the error message that the control is missing. im running as an administrator.
is there anything else i must do.
Regards
|
|
|
|
|
It's probably missing a dependancy. Google for "Dependancy Walker" and use that to open the tabctl32.ocx file and it'll show you the .DLL's it's trying to load.
|
|
|
|
|
Is there some way to stop Windows from hiding a notifyIcon? I'm not afraid of API calls if they're necessary. We're developing a program that will minimize to the tray and it's important that it's icon is always visible (it updates the user by changing the icon as events occur).
I'm sure there's a way, since the Windows icons do it.
Thanks,
Ray Phillips
Jeff Computers
StudyX.com
|
|
|
|
|
NotifyIcons do what you tell them to do, they don't just disappear. In fact you have to add extra code (a call to Dispose) to make sure they disappear when your app exits. If your NI disappears inadvertently it tells me it is being garbage collected, which implies you didn't give it enough scope. Is it a member of your form class? It should not be a local variable!
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
What I meant was, if the user has auto hiding of their notify icons turned on, the icon gets "hidden" (where you have to push the arrow to see the "hidden" icons). We need ours to always be visible. It's not that the icon is disappearing, per se; it's being hidden until the user clicks that arrow.
Sorry for the confusion
-Ray
Jeff Computers
StudyX.com
|
|
|
|
|
You must be using Windows 7 then. I expect the official stance will be: the behavior of NotifyIcons is a user's choice, and should not be set by the app; the user can:
- have inactive icons hidden (the default?);
- have all icons show;
- choose for each individual icon (the choice persists, seems associated with the EXE file, not the process).
I am unaware of any code that would allow an app to change its own NotifyIcon behavior.
However, there is this article that may interest you: WPF NotifyIcon[^].
PS: the Windows icons that always show are "system icons", they are handled differently; I don't expect the NotifyIcon class maps to them at all.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
XP allows the notify icons to be hidden as well. There is a setting in XP to allow you to change an icon to be always hide, or always show. So even if you were to programmatically change it, you might have to try to detect if the user changed it manually and to change it back.
Steve Maier
|
|
|
|
|
Ho hum... that's what I was afraid of. lol. Thanks for the replies. Looks like I'll have to find a "creative solution".
The Code Project and it's community ROCKS!
-Ray
Jeff Computers
StudyX.com
|
|
|
|
|