vb.net中的类 [英] class in vb.net

查看:89
本文介绍了vb.net中的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经创建了用于登录的3层架构程序...用户将使用用户名和密码作为参数...这是我的程序代码


应用层:

导入System.Data
导入System.Data.SqlClient
导入System.Security.Principal
导入System.Threading
导入System.IO
导入System.Text
导入System.Collections.Generic
导入bal.cbal
命名空间应用
结束命名空间
公共类capp
私人Sub OK_Click(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理OK.Click
昏暗验证为新bal.cbal
Dim dat As New bal.cbal
昏暗使用作为字符串= UsernameTextBox.Text
Dim pas As String = PasswordTextBox.Text
验证(使用,PAS)
Me.Close()
结束子
Private Sub Cancel_Click(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理Cancel.Click
Me.Close()
结束子
私有Sub capp_Load(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理MyBase.Load
" TODO:这行代码将数据加载到" LoginDataSet.details"表中.您可以根据需要移动或删除它.
Me.DetailsTableAdapter.Fill(Me.LoginDataSet.details)
结束子
结束类



业务逻辑层:


导入System.Data
导入System.Data.SqlClient
导入System.Security.Principal
导入System.Threading
导入System.IO
导入System.Text
命名空间cbal
公共课bal
暗淡检查为新的dal.cdal
昏暗的myDS作为dal.cdal
昏暗的登录尝试作为整数
公共函数verify(ByVal使用为字符串,ByVal pas为字符串)作为字符串
如果(use.Length> 10)然后
引发新异常(用户名必须至少为10个字符")
ElseIf(长度超过6)(Pas.Length> 6)然后
引发新异常(密码必须至少为6个字符长")
如果结束
loginattempts + = 1
如果loginattempts> = 3,则
MsgBox(登录尝试失败太多",MsgBoxStyle.Exclamation)
其他
MsgBox(找不到用户名.请重试",MsgBoxStyle.Exclamation)
如果结束
返回myDS
最终功能
结束类
结束命名空间




数据层:

导入System.Data
导入System.Data.SqlClient
导入System.Text
导入System.Security.Principal
导入System.Threading
导入System.IO
命名空间dal
公共类Cdal
Dim strConnect As String =数据源= pc325;初始目录= pubs;集成安全性= SSPI;"
Dim Con As SqlConnection =新的SqlConnection(strConnect)
暗淡登录为对象
将mySDA昏暗为对象
将myDS作为对象变暗
子Main()
试试
Con.Open()
Console.WriteLine(连接已打开")
捕获为SqlException
Console.WriteLine("Error:"& ex.ToString())
终于
Con.Close()
Console.WriteLine(连接已关闭")
结束尝试
结束子
公共功能检查(ByVal用作字符串,ByVal用作字符串)
如果(use = use And pas = pas)然后<​​br/> Console.WriteLine(登录成功")
其他
Console.WriteLine(无效的名称/密码")
如果结束
Dim com As New SqlCommand("select * from details from use =''"& use&''pas ="& pas&"'',Con)
昏暗的SqlDataAdapter作为新的mySDA
将mySDA设置为新的SqlDataAdapter(登录)
将昏暗的数据集设置为新的myDS
mySDA.Fill(myDS)''cmdObj.Dispose()
Con.Close()
返回myDS
最终功能
私有子SqlDataAdapter(作为对象的ByVal p1)
引发新的NotImplementedException
结束子
结束类
结束命名空间
k ..
错误出现在应用程序层..
它在第19行上给出错误tat类"WindowsApplication2.bal.cbal"无法索引,因为它没有默认属性


i have created 3 tier architcture program for login...user wil use username and password as parameters...here is my code for program


application tier:

Imports System.Data
Imports System.Data.SqlClient
Imports System.Security.Principal
Imports System.Threading
Imports System.IO
Imports System.Text
Imports System.Collections.Generic
Imports bal.cbal
Namespace app
End Namespace
Public Class capp
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim verify As New bal.cbal
Dim dat As New bal.cbal
Dim use As String = UsernameTextBox.Text
Dim pas As String = PasswordTextBox.Text
verify(use, pas)
Me.Close()
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub
Private Sub capp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
''TODO: This line of code loads data into the ''LoginDataSet.details'' table. You can move, or remove it, as needed.
Me.DetailsTableAdapter.Fill(Me.LoginDataSet.details)
End Sub
End Class



business logic tier:


Imports System.Data
Imports System.Data.SqlClient
Imports System.Security.Principal
Imports System.Threading
Imports System.IO
Imports System.Text
Namespace cbal
Public Class bal
Dim check As New dal.cdal
Dim myDS As dal.cdal
Dim loginattempts As Integer
Public Function verify(ByVal use As String, ByVal pas As String) As String
If (use.Length > 10) Then
Throw New Exception("username must be atleast 10 characters")
ElseIf (pas.Length > 6) Then
Throw New Exception("password must be atleast 6 charcters long")
End If
loginattempts += 1
If loginattempts >= 3 Then
MsgBox("Too many failed login attempts", MsgBoxStyle.Exclamation)
Else
MsgBox("User Name not found. Please try again", MsgBoxStyle.Exclamation)
End If
Return myDS
End Function
End Class
End Namespace




data tier:

Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports System.Security.Principal
Imports System.Threading
Imports System.IO
Namespace dal
Public Class cdal
Dim strConnect As String = "Data Source=pc325;Initial Catalog=pubs;Integrated Security=SSPI;"
Dim Con As SqlConnection = New SqlConnection(strConnect)
Dim login As Object
Dim mySDA As Object
Dim myDS As Object
Sub Main()
Try
Con.Open()
Console.WriteLine("Connection Opened")
Catch ex As SqlException
Console.WriteLine("Error: " & ex.ToString())
Finally
Con.Close()
Console.WriteLine("Connection Closed")
End Try
End Sub
Public Function check(ByVal use As String, ByVal pas As String)
If (use = use And pas = pas) Then
Console.WriteLine("login success")
Else
Console.WriteLine("Invalid name/password")
End If
Dim com As New SqlCommand("select * from details where use =''" & use & "''pas =''" & pas & "''", Con)
Dim SqlDataAdapter As New mySDA
Dim mySDA As New SqlDataAdapter(login)
Dim DataSet As New myDS
mySDA.Fill(myDS) ''cmdObj.Dispose()
Con.Close()
Return myDS
End Function
Private Sub SqlDataAdapter(ByVal p1 As Object)
Throw New NotImplementedException
End Sub
End Class
End Namespace
k..
the error s coming in application tier..
it s giving the error on line 19 tat Class ''WindowsApplication2.bal.cbal'' cannot be indexed because it has no default property

推荐答案

它总是Namspace.ClassName

您已编写ClassName.Namspace,即
It''s always Namspace.ClassName

You have written ClassName.Namspace i.e
Imports bal.cbal


这篇关于vb.net中的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆