|
Thanks all!
I found it, just thought I'd pass it on.
uxFileLstvw.FocusedItem.Text
Thanks,
Karen
Nooobie to OOP and VB.Net 2005
|
|
|
|
|
Hello,
This is my first go at implementing an interface for a connection, reader, ect.. and it is also my first go at a three tier design,Although i have been studing this for some time now tring to put all of these pieces togeather. I feel like i am getting to a point that i can comfortably work with this type of suggest design.
I am having trouble connecting to the database. The error that i am getting says that the object is not set to an instant of an object,, ( ok so i might say hey,, i kown what this is, but with the interfaces there is no way to just say, dim my iDBC as new idbconnection)'' Can someone please look at my code and help me pinpoint what needs to be corrected. Not just the connection but the rest of the implementation.It would really help me out alot, because i am into new waters.
===================
*** this is what i have created to test with so that once i can get going with this then i can move forward with the real stuff.. I would be so greatful to have developers that can point out a better way of strongly typeing my database here.. One of the reasons that i want to learn implementing this this way is because from what i understand this is the correct way(maybe not exactly the way that i have it ).. Any help at all would be great!!!
From the form page......................
-------------------------------------------------------------------
Imports DA = SuperCenter.DataAccess.Blinds
Namespace SuperCenter.Web
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GetNumbers()
End Sub
'
Public Sub GetNumbers()
Dim pk As Int32 = 3
With New DA
ddl.DataSource = .GetNumbers(Request.QueryString("pk"))
ddl.DataBind()
End With
End Sub
End Class
End Namespace
============================================================
===============================================
dataaccess
=============================================
Imports System.Data.SqlClient
Imports DATA = SuperCenter.Data
Namespace SuperCenter.DataAccess
Public Class Blinds
Private _Datareader As IDataReader
Private _cnn As IDbConnection
Const DATABASE = "Data Source=Desktop; Initial Catalog=TEST; Trusted_Connection=True"
'
Public Sub New()
With _cnn
.ConnectionString = DATABASE **** My error is right here****
End With
End Sub
'
Public Function GetNumbers(ByVal pk As Int32) As Data.Blinds
'
GetNumbers = SharedAccess("BlindGetNumbers", "@pk", pk)
End Function
'
Private Function SharedAccess(ByVal BlindSprocName As String, _
ByVal parmName As String, _
ByVal parmvalue As Int32) As Data.Blinds
Dim B As Data.Blinds
Dim BL As New Data.BlindList
Dim cmd As IDbCommand
With cmd
.CommandType = CommandType.StoredProcedure
.CommandText = BlindSprocName
Dim ipram As IDataParameter
With ipram
.DbType = DbType.Int32
.ParameterName = parmName
.Value = parmvalue
End With
.Parameters.Add(ipram)
End With
_cnn.Open()
_Datareader = cmd.ExecuteReader
While _Datareader.Read
BL.add(New Data.Blinds(_Datareader("Numbers")))
End While
_cnn.Close()
_Datareader.Dispose()
_Datareader.Close()
'
If _cnn.State = ConnectionState.Open Then
_cnn.Close()
If _Datareader.IsClosed = False Then
_Datareader.Close()
_Datareader.Dispose()
End If
End If
End Function
'
End Class
End Namespace
=======================================================
Property page---------------------------
================================================
Namespace SuperCenter.Data
Public Class Blinds
Private _Width As String
Private _Tall As String
Private _Numbers As String
Private _Colors As String
Private _Extras As String
Public Sub New()
End Sub
Public Sub New(ByVal Numbers As String)
_Numbers = Numbers
End Sub
'
Public Sub New(ByVal Width As String, _
ByVal Tall As String, _
ByVal Numbers As String, _
ByVal Colors As String, _
ByVal Extras As String)
_Width = Width
_Tall = Tall
_Numbers = Numbers
_Colors = Colors
_Extras = Extras
End Sub
'
Public Property Width() As String
Get
Return _Width
End Get
Set(ByVal Value As String)
_Width = Value
End Set
End Property
'
Public Property Tall() As String
Get
Return _Tall
End Get
Set(ByVal Value As String)
_Tall = Value
End Set
End Property
'
Public Property Numbers() As String
Get
Return _Numbers
End Get
Set(ByVal Value As String)
_Numbers = Value
End Set
End Property
'
Public Property Colors() As String
Get
Return _Colors
End Get
Set(ByVal Value As String)
_Colors = Value
End Set
End Property
'
Public Property Extras() As String
Get
Return _Extras
End Get
Set(ByVal Value As String)
_Extras = Value
End Set
End Property
End Class
End Namespace
===================================================
CollectionBase page
==============================================
Namespace SuperCenter.Data
Public Class BlindList : Inherits CollectionBase
'
Public Sub New()
End Sub
'
Public Function add(ByVal blind As Blinds) As Int32
Return Me.add(blind)
End Function
'
Default Public ReadOnly Property item(ByVal index As Int32)
Get
Return CType(item(index), Blinds)
End Get
End Property
'
End Class
End Namespace
|
|
|
|
|
OK, first of all, the reason why you would create a generic interface for data access is to hide the database implementation from your application.
For example, if you want to write a single front-end application that will work with both Access and SQL Server, then you wouold create generic interfaces like IConnection, IParameter, ICommand. Your application would work with these interfaces only.
Then you would have two families of classes, one for Access, one for SQL Server, that implement the common interfaces.
In your code, you are explicitly using the SqlClient family of data access. Now, there is absolutely nothing wrong with doing this. But there is no point in doing both - if you are going to explicitly bind your application to SQL Server, there is no point in going through interfaces.
Assuming you want to use interfaces, and not bind to a specific database type, you have to create implementation classes. As you point out, you cannot declare an Interface class as New. That is because the interface is only a definition. Instead what you need to do is create an implementation class that returns objects that implement the interfaces.
You never actually work with a SqlConnection. Instead you work through a custom class that entirely encapsulates the connection object for you.
This is difficult to explain.
There is a book, however, that has a full set of working examples for using indirect data access through interfaces:
Professional Design Patterns in VB.NET, by Fischer, et al. Published by a-Press. I think their code is available on the publishers website, but you really need the book to understand the concepts.
|
|
|
|
|
thank you for your help!
I will go with your suggestion and lay off of the Interfaces, i believe it is beyond my brain at this point! ~ However i will look for the book in the coming weeks...
erik..
|
|
|
|
|
Creating a truly functional abstract data access interface/implementation architecture is extremely challenging. Fischer et al devote almost 50 pages to the subject, and at the end they have only implemented two generic objects - DataReader and DataSet objects. A Data Reader is a forward, read only object - not too complicated. And a DataSet is already platform independent by nature.
And they "cheat" a lot too - their design assumes all parameters are strings, for example.
It's not easy. People struggle with these concepts for a long time. The best thing to do is start small - create small experimental projects until you rfeally understand how the interface and implementations really fit together.
|
|
|
|
|
Greetings!
Private Sub uxGpDirectoryTree_DoubleClick( _
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles uxGpDirectoryTree.DoubleClick
uxBaseDirCmbbx.Text += uxGpDirectoryTree.SelectedNode.Text + "\"
End Sub
Everytime this code is invoked, it invokes another method (uxBaseDirCmbbx.SelectedIndexChanged) - except for the last subfolder. I assume this is because the Text property has changed.
So why not on the last subfolder?
Thanks,
Karen
Nooobie to OOP and VB.Net 2005
|
|
|
|
|
Greetings!
I'm having trouble with my treeview. Once I select a node from the treeview, it invokes the AfterSelect event, re-fills my nodes and the re-executes the AfterSelect event (again) - thus re-filling my node tree:
Private Sub uxGpDirectoryTree_AfterSelect( _
ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) _
Handles uxGpDirectoryTree.AfterSelect
Me.StartDir += uxGpDirectoryTree.SelectedNode.Text + "\"
call fillDirectoryTree()
End Sub
Private Sub fillDirectoryTree()
Dim arrSubfolders() As DirectoryInfo
arrSubfolders = New DirectoryInfo(Me.StartDir).GetDirectories
uxGpDirectoryTree.Nodes.Clear()
For Each subfolder As DirectoryInfo In arrSubfolders
uxGpDirectoryTree.Nodes.Add(subfolder.Name)
Next
End Sub
I have debugged and it does cycle more than once. Any help would be greatly appreciated.
Thanks,
Karen
Nooobie to OOP and VB.Net 2005
|
|
|
|
|
Not exactly what I wanted, but DoubleClick seams to work.
Thanks,
Karen
Nooobie to OOP and VB.Net 2005
|
|
|
|
|
It looks like you're wiping out your entire TreeView, then refilling it with the subdirectories under the node that was selected. Is this really what you want?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hello frnds can u tell me how v can lock the movement of the alt+clrt+tab keys in a vb application
|
|
|
|
|
What do you mean by "lock the movement of the alt-ctrl-tab keys"? What does "lock the movement mean". Ctrl-Alt-Tab doesn't really do anything specific so it's hard to tell what you want this to do.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hello buddy,
Alt+ctrl+tab key is used to move among the different applicaitons running on the window platform. So i want to stop the switching of the programs when my application is running on the system. if u knw pls help me
|
|
|
|
|
It's Alt-Tab and Alt-Shift-Tab that do that. The Ctrl key doen't do anything.
You'll have to write a low level keyboard hook to do this. Search the articles and Google for "vb.net keyboard hook" and you'll find some examples.
I wouldn't recommend doing this unless you had very specific reasons for including this "feature". "Just to have it" will get your app uninstalled in a heartbeat.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I need some help on how to correctly use BeginInvoke.
Here's the scenario:
I have a panel on my form called Panel1 and I have a button that I use to execute a query that can have multiple resultsets.
I'm executing the query asynhcronously and then I dynamically add x number of datagrids to Panel1, where x is the number of resultsets returned by the query.
At the point at which I add the datagrid to panel1 the code stops executing and nothing gets added to Panel1.
I've looked at using the Control.BeginInvoke method but ended up making more of a mess of things.
Hope someone can help.
Thanks in advance.
The code looks something like this:
<br />
<br />
<br />
<br />
Public Delegate Sub MakeGrids(ByVal ResultsTable As DataTable)<br />
<br />
Private Sub ExecuteThreadedQuery()<br />
<br />
'do various things and fill a dataset with the query results<br />
<br />
'loop through each table in dataset<br />
For Each table as datatable in dataset.tables<br />
<br />
<br />
Dim NewGrid As New MakeGrids(AddressOf AddResultsGrid)<br />
<br />
'call the AddResultsGrid sub using BeginInvoke<br />
NewGrid.BeginInvoke(ResultsTable, Nothing, Nothing)<br />
<br />
<br />
Next <br />
<br />
<br />
End Sub<br />
<br />
<br />
Private Sub AddResultsGrid(ByVal ResultsTable As DataTable)<br />
<br />
Dim ResultsGrid as DataGrid<br />
<br />
'assign relevant properties to the grid and bind it to the ResultsTable which has been fed through<br />
<br />
<br />
'Add it to the panel<br />
Panel1.Controls.Add(ResultsGrid) '***AT THIS POINT THE CODE STOPS EXECUTING AND NOTHING IS ADDED TO THE PANEL<br />
<br />
<br />
<br />
End Sub<br />
<br />
<br />
|
|
|
|
|
Hello!
Suppose i want to navigate from one form (Form1) to another form (Form2), then i want to cancel the first form (Form1) and then only want to show second form (Form2). What should i do?
Regards,
Arfan Qadir
|
|
|
|
|
just do this
form1.hide
form2.show
V.Gopi
|
|
|
|
|
Just be advised that if you follow those steps and hide form1, the resources allocated with it still exist. The form really still exists but you can't see it.
|
|
|
|
|
Hello Everybody in this Discussion board!
I want to take input (like 2x^2+Sinx-log(x)-9) from user and then want to calculate its value at any value of x (like 2.6), then what should i do in VB.NET?
Thanx in advance for your assistance
Bye
Arfan Qadir
|
|
|
|
|
All you have to do is search the articles for "math expression parser"[^] and you'll come up with a bunch of examples.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Anyone know how to write a service to receive faxes?
|
|
|
|
|
The scenario can be best described as the following.
A form is created with only a label. A keyup event is added to the form so that when a key is pressed the value of that key is added to the label.
Now when I add a couple of radio buttons and a standard button to the same form, this procedure does not work.
I want the form to handle the key event not some control. Why can I not set the form to have focus when other controls are present?
I hope this makes sense!
Thanks!
|
|
|
|
|
Set the KeyPreview propery of your form to TRUE.
|
|
|
|
|
Hello,
I am trying to export the contents of a datagrid to Excel.
Here's the code I have so far:
<small> 'Fire up an Excel instance
Dim ExcelApp As New Excel.Application
ExcelApp.Visible = True
Dim workbooks As Workbooks = ExcelApp.Workbooks
Dim workbook As _Workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet)
Dim sheets As Sheets = workbook.Worksheets
Dim worksheet As _Worksheet = CType(sheets.Item(1), _Worksheet)
'Put some data on the Worksheet -- This doesn't work, but throws no errors
Dim nCell As Integer = 5
Dim Range2 As Range = worksheet.Range("A1", "E1")
Dim array2(nCell) As Integer
Dim i As Integer
For i = 0 To (array2.GetLength(0)) - 1
array2(i) = i + 1
Next
Dim args2(1) As Object
args2(0) = array2
Range2.GetType().InvokeMember("Value", BindingFlags.SetProperty, Nothing, Range2, args2)</small>
Everything works except the last line. Actually, the only thing I have been successful at doing was getting the Excel app to fire up. Beyond that I am left looking at beautiful, although empty, white cells.
I'm using VS.Net 2005 latest beta.
It seems simple enough... Read a datagrid, send the results to an Excel worksheet. I would use the more accepted method of using Response.Write, but due to our website configuration, things get all screwed up with using a Master page and <form> tags.
If anyone can help me out of this bind, I would be a very happy programmer.
|
|
|
|
|
AFAICT, you can't bind an array to an Excel Range. You have to inster the values into the cells, one at a time.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
...that seems to be where I am stuck at - inserting the values one at a time.
Using the code:
Dim args1(1) As Object
args1(0) = nCell
Range1.GetType().InvokeMember("Value", BindingFlags.SetProperty, Nothing, Range1, args1)
..I get an error that states: "Public member 'GetType' on type 'Range' not found."
Since I'm using VS.Net 2005, I am wondering if there is a library I am missing or if the function has been removed altogether.
That is where I am at. Inserting the data, even a single cell value is proving to be my ticket to insanity. So close, yet so far.
|
|
|
|
|