|
This is how i got there:
Install the WMI Extensions
Open Visual Studio
New Project
Go to Server Explorer / Management Classes
Right Click -> Add Class
Drill down to root\CIMV2 : Printers
Click Add and OK
Right click on the new node -> Generate Managed Class
-- modified at 21:39 Friday 27th January, 2006
|
|
|
|
|
First, toss the "Generated" garbage in the trash. Do it by hand so you can understand what's going on and have greater control over it. It also makes asking and answering questions a whole lot easier.
Dim searcher As New ManagementObjectSearcher("SELECT * FROM Win32_Printer")
Dim prn As ManagementObject
For Each prn In searcher.Get()
Console.WriteLine("Printer Name = " & prn("Name").ToString())
Next share
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
Ummm.... The link you posted doesn't have anything to do with returning all the printer names on the machine.....??
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Need help from a crystal reports Guru.
I am trying to display values from the text boxes on this one form. The crystal report is already connected to the database and all the fields are there. When I try to run the report it pulls all the data from the DB. Below is the code. Please help!
Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load<br />
Dim myDS As New Dataset1<br />
Dim rptdata As New dbAccess<br />
Dim rptval As New Change<br />
<br />
Dim rpt As New Chgmgt<br />
rpt.SetDataSource(myDS)<br />
CrystalReportViewer1.ReportSource = rpt<br />
<br />
Dim LogNumber1 As Integer<br />
Dim Daterequested1 As String<br />
Dim TargetDate1 As String<br />
Dim Time1 As String<br />
Dim RequestedBy1 As String<br />
Dim ProjectName1 As String<br />
Dim ChangeDescription1 As String<br />
Dim Users1 As String<br />
Dim Department1 As String<br />
<br />
LogNumber1 = rptval.LogNumber<br />
Daterequested1 = rptval.DateRequested<br />
TargetDate1 = rptval.TargetDate<br />
Time1 = rptval.Time<br />
RequestedBy1 = rptval.RequestedBy<br />
ProjectName1 = rptval.ProjectName<br />
ChangeDescription1 = rptval.ChangeDescription<br />
Users1 = rptval.Users<br />
Department1 = rptval.Department<br />
<br />
<br />
End Sub
------------------------------------------------------------------------
|
|
|
|
|
Hi everyone
Is it possible to use 1 database, to be accessed through a VB web form as well as through a VB windows application ? If so, can someone give me some direction on this ?
Derek
|
|
|
|
|
Sure. All you need to do is keep all your database code in a data layer class. You can then reuse that code in any UI application you want. You're looking for information on 3-tier design.
You can find a pretty good example here[^].
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
Hi, I'm new to VB.NET. I use a datalist to display and edit my records form Access database.
I got problems whenever I try to update or delete a record, it gives me "The ConnectionString property has not been initialized" error. Does anybody has any idea how to solve this problem? Where should I change the code? Please show me how to do it. Thanks.
Here's the code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
LoadData()
End If
End Sub
Public Sub LoadData()
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("CampusVoting.mdb")
myconnection = New OleDbConnection(strconn)
cmdReq.CommandText = "select * from News"
cmdReq.Connection = myconnection
cmdReq.Connection.Open()
dr = cmdReq.ExecuteReader
NewsList.DataSource = dr
NewsList.DataBind()
cmdReq.Connection.Close()
End Sub
Sub Del_Command(ByVal sender As Object, ByVal e As DataListCommandEventArgs)
Dim title As String
title = NewsList.DataKeys(e.Item.ItemIndex)
Dim cm As New OleDbCommand("delete from News where NewsID = " & title & "", myconnection)
cm.Connection.Open()
cm.ExecuteNonQuery()
cm.Connection.Close()
LoadData()
End Sub
Sub Cancel_Command(ByVal sender As Object, _
ByVal e As DataListCommandEventArgs)
NewsList.EditItemIndex = -1
LoadData()
End Sub
Sub Edit_Command(ByVal sender As Object, _
ByVal e As DataListCommandEventArgs)
NewsList.EditItemIndex = e.Item.ItemIndex
LoadData()
End Sub
Sub Update_Command(ByVal sender As Object, _
ByVal e As DataListCommandEventArgs)
Dim tbox As TextBox
Dim Title_id As String
Dim Title, Descr As TextBox
title_id = NewsList.DataKeys(e.Item.ItemIndex)
Title = e.Item.FindControl("NewsTitle")
Descr = e.Item.FindControl("NewsDesr")
Dim cmd As New OleDbCommand("Update News set NewsTitle = '" & Title.Text & "', NewsDesr='" & Descr.Text & "' where NewsID=" & Title_id & "", myconnection)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
NewsList.EditItemIndex = -1
LoadData()
End Sub
|
|
|
|
|
The error is pretty obvious. You're first problem is that your using class scoped (or global if you must use the term) variables for hold your database objects. This is really bad practice.
I would suggest moving your database code to a data layer class. This removes your UI from handling the database stuff itself and encapsulates the data so you can easily reuse it from a Windows Forms app, if you so choose.
The problem is pretty obvious if you follow your code. An ASP.NET app is only alive for the time it takes to generate a single HTML page. Once the page is sent to the client, your app effectively quits. When the use clicks on a button on the HTML page, a request is sent back to your IIS server and another instance of your app is launched. It knows nothing of the previous instances "global" variables that you setup.
Knowing this, follow your code. The only time you ever initialize the strConn or myConnection variables is on the first page that is sent to the client. After that, you never initialize them again when the user clicks on the various control on your page. Remember that "IsPostBack" statement?
Basically, there is no "change this line to this" that's going to fix your code. It needs a major rewrite to get this datbase code to work...
Public Class DataLayer
Public Shared Function GetDatabaseConnection() As OleDbConnection
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("CampusVoting.mdb"))
Return conn
End Function
.
.
.
End Class
Get the idea?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 10:33 Friday 27th January, 2006
|
|
|
|
|
Hi,
Thanks for the reply, now I got the idea how to avoid that error again.
|
|
|
|
|
I am trying to disable a tab page. In this example, I have a tab control with 3 tab pages. What I want to do is if I select say Tab Page 2, then this is disabled and will not let me view the contents.
Here is my code
Private Sub TabControl1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.Click
If TabControl1.SelectedIndex = 1 Then
TabPage2.Enabled = False
End If
End Sub
I have also tried TabPage2.visible = false
Nothing seems to happen when I try the above. What am I doing wrong?
|
|
|
|
|
The TabPage cannot be Disabled. You actually have to remove it from the TabControl's TabPages collection and add it back when you need to show it.
In practice, this is not a good UI design. Tab's put back into the collection will appear at the end of the tab control, effectively rearranging the tabs. There is no way to sort them without removing ALL the TabPage controls and re-adding them in the order that you want them to appear.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote: There is no way to sort them without removing ALL the TabPage controls and re-adding them in the order that you want them to appear.
I also used to have a problem with the above problem like the person that post the previous thread. If we could not hide or disable, how about the visitble property? What is the meaning of visible property for each tab page if it still could not hide the page that we want to hide?
On the other hand, if we remove the any page, how about the control on that tab page? Do we need to add it again or not?
|
|
|
|
|
TabPage inherits from Control. Control is what is supplying the Enabled and Visible properties. But, in TabPage, they're not wired up to do anything, so they don't work.
When you remove the TabPage from the TabPages collection, you're just removing an object from a collection. If you don't save that object in another variable or collection somewhere first, it's reference count will drop to 0 and it, and all the controls on it, will be destroyed.
If you save the TabPage somewhere else, then nothing will happen to the controls on that page. They'll still be alive and well, so long as their parent TabPage object is still alive. All you have to do is re-add the TabPage back to the TabPages collection of any TabControl object.
You could even move an entire TabPage, controls and all, from one TabControl to another.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote: If you don't save that object in another variable or collection somewhere first, it's reference count will drop to 0 and it, and all the controls on it, will be destroyed.
How to save a TabPage collection?
Dave Kreskowiak wrote: You could even move an entire TabPage, controls and all, from one TabControl to another.
How to move an entire TabPage and its control from one TabControl to another?
|
|
|
|
|
Dim savedTabPage As TabPage = TabControl.TabPages(3)
NewTabControl.TabPages.Add(savedTabPage)
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thank you very much for your sample code.
|
|
|
|
|
I done the following and it seems to work.
TabControl1.TabPages.Remove(TabControl1.TabPages(2))
The reason I want to hide/disable a tab page is that, depending on your authority depends if you see the contents of that tab page. Since I cannot hide or disable the tab page, this seems the best way.
|
|
|
|
|
I get an error when I try the following....
TabControl1.TabPages.Remove(TabControl1.TabPages(4))
TabControl1.TabPages.Remove(TabControl1.TabPages(3))
TabControl1.TabPages.Remove(TabControl1.TabPages(2))
TabControl1.TabPages.Remove(TabControl1.TabPages(1))
TabControl1.TabPages.Remove(TabControl1.TabPages(0))
TabControl1.TabPages.Add(TabControl1.TabPages(0)) <==== Error here
TabControl1.TabPages.Add(TabControl1.TabPages(1))
TabControl1.TabPages.Add(TabControl1.TabPages(3))
TabControl1.TabPages.Add(TabControl1.TabPages(4))
What is it I am doing wrong.
|
|
|
|
|
Because you have removed the tab pages from the TabControl1.TabPages collection, they are no longer in that collection. You can't ask for a tab page in a collection from which you just removed it. You have to store the tab pages you removed somewhere else, like an arraylist (or in .net 2.0 a List(Of TabPage)).
private removedPages As New List(Of TabPage)
removedPages.Add(TabControl1.TabPages(4))
removedPages.Add(TabControl1.TabPages(3))
removedPages.Add(TabControl1.TabPages(2))
removedPages.Add(TabControl1.TabPages(1))
removedPages.Add(TabControl1.TabPages(0))
TabControl1.TabPages.Remove(TabControl1.TabPages(4))
TabControl1.TabPages.Remove(TabControl1.TabPages(3))
TabControl1.TabPages.Remove(TabControl1.TabPages(2))
TabControl1.TabPages.Remove(TabControl1.TabPages(1))
TabControl1.TabPages.Remove(TabControl1.TabPages(0))
TabControl1.TabPages.Add(removedPages(0)) <==== Error here
TabControl1.TabPages.Add(removedPages(1))
TabControl1.TabPages.Add(removedPages(3))
TabControl1.TabPages.Add(removedPages(4))
Hope this helps!
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick || Fold With Us! || Pensieve || VG.Net ||
|
|
|
|
|
You beat me to it! Thanks Marc!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
How do i make a label transparent? Do i have to create a new class of label with new properties?
rzvme
|
|
|
|
|
All you have to do is set it's BackColor property to Color.Transparent .
myLabel.BackColor = Color.Transparent
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 10:16 Friday 27th January, 2006
|
|
|
|
|
Label.backcolor = color.transparent
|
|
|
|