|
-
Feb 24th, 2009, 08:01 AM
#1
Thread Starter
Member
SQL SERVER class
Hello guys, I have managed to connect to SQL server with a simple connection string, and work with table, but I want to biuld a class for this and understand, how class, namespace and properties work.
Code:
Namespace SqlDataProvider
Public NotInheritable Class SqlDatabase
#Region " Local Property Declarations "
Dim _connectionString As String
#End Region
#Region " Constructor "
'''<summary>
''' Initializes a new instance of the ADO.SqlDatabase class.
''' </summary>
''' <param name="connectionString">The connection used to open the SQL Server database.</param>
Public Sub New(ByVal connectionString As String)
_connectionString = "Data Source=(local); Initial Catalog=Test ; UId =" & Login.UsernameTextBox.Text & _
"; Pwd =" & Login.PasswordTextBox.Text & ";"
End Sub
#End Region
#Region " Public Properties "
''' <summary>
''' Gets or sets the string used to open a SQL Server database.
''' </summary>
''' <returns>The connection string that includes the source database name, and other parameters needed to establish the initial connection.</returns>
Public Property ConnectionString() As String
Get
Return _connectionString
End Get
Set(ByVal value As String)
_connectionString = value
End Set
End Property
#End Region
I have found the above code. I have added a login form in my project, and I want connectionstring to read username.text and passwd.text, from loginform.
So as I can understand, connectionstring reads these strings, and with ConnectionString property returns me if these are right for my database or not.
I can't figure out how can I call Sub New from my class, and connectionstring property. Namespace is needed or should I remove them, and change class name?
I have tried to call sub new
New(), or SqlDataProvider.New with no luck.
What am I doing wrong?
Last edited by manin; Feb 24th, 2009 at 08:45 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|