大哥们,帮帮小弟我吧,小弟正在做毕业设计,遇上了一个问题,无从下手了.
我用sql2000 建立一个家庭理财数据库其次建立管理员表
其中字段为如下:
用户名 varchar
密码 varchar
'定义一个公用模块
Imports System.Data.SqlClient
Module Module1
Public Ds As New DataSet
Public sqlstr As String
Public constr As String = "integrated security=true;server=.;database=家庭理财"
Public conn As New SqlConnection(constr)
'定义一个数据连接对象,并初始化
End Module
------------------------------------------------------------------------------------'在窗体中调用
Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
Dim User As String
Dim Password As String
#Region " Windows 窗体设计器生成的代码 "
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If MsgBox("您真的不登录系统吗?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "退出登录系统") = MsgBoxResult.Yes Then
Application.Exit()
Else
Exit Sub
End If
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If MsgBox("您真的不登录系统吗?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "退出登录系统") = MsgBoxResult.Yes Then
e.Cancel = False
Else
e.Cancel = True
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim f2 As New Form2
User = Me.ComboBox1.Text.Trim
Password = Me.TextBox1.Text.Trim
Try
sqlstr = "select * from 管理员"
Dim da As New SqlDataAdapter(sqlstr, conn)
Dim ds As New DataSet
Dim row As DataRow
da.Fill(ds, "管理员")
Dim dt As DataTable = ds.Tables("管理员")
Dim rows As DataRow() = dt.Select("用户名='" & User & "'")
row = rows(0)
If User <> "" And Password <> "" And User = row.Item("用户名") And Password = row.Item("密码") Then
i = MsgBox("恭喜你已成功登陆", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "系统消息")
f2.Show()
Me.Finalize()
Else
i = MsgBox("密码和账号不符,请重试,并检查该账号是否存在。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "系统登录失败")
Me.TextBox1.Text = ""
End If
Static n As Integer
n = n + 1
If n = 4 Then
i = MsgBox("对不起你不是该用户!", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxHelp, "系统消息")
Close()
End If
Catch
MsgBox(Err.Description)
Exit Sub
End Try
End Sub
End Class
结果在调试的时候 出现这个错误
未将对象引用设置到对象的实例
就这个我不知道何解 请大家帮帮我 --------------------编程问答-------------------- 设断点..调试一下. --------------------编程问答-------------------- 你的代码不完整,例如我就没看见你在哪里打开连接了。
看不见你贴上来的代码有什么问题,可能是其他地方错了,你看看你错在哪里停下来的,估计是某个对象没有NeW,或返回对象的某个操作失败了,你却对用来接收对象的变量进行了炒作。 --------------------编程问答-------------------- 我设了断电 调试了一下
说是 try 总是中断 --------------------编程问答-------------------- 我用sql2000 建立一个家庭理财数据库
其次建立管理员表
其中字段为如下:
用户名 varchar
密码 varchar
'定义一个公用模块
Imports System.Data.SqlClient
Module Module1
Public Ds As New DataSet
Public sqlstr As String
Public constr As String = "integrated security=true;server=.;database=家庭理财"
Public conn As New SqlConnection(constr)
'定义一个数据连接对象,并初始化
End Module
------------------------------------------------------------------------------------'在窗体中调用
Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
Dim User As String
Dim Password As String
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button2 = New System.Windows.Forms.Button
Me.Button1 = New System.Windows.Forms.Button
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'ComboBox1
'
Me.ComboBox1.Location = New System.Drawing.Point(104, 24)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(121, 20)
Me.ComboBox1.TabIndex = 11
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(104, 64)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(120, 21)
Me.TextBox1.TabIndex = 10
Me.TextBox1.Text = ""
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(176, 112)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(48, 23)
Me.Button2.TabIndex = 9
Me.Button2.Text = "退出"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(104, 112)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(48, 23)
Me.Button1.TabIndex = 8
Me.Button1.Text = "登录"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(48, 64)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(56, 23)
Me.Label2.TabIndex = 7
Me.Label2.Text = "密 码:"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(48, 32)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(64, 23)
Me.Label1.TabIndex = 6
Me.Label1.Text = "用户名:"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(292, 168)
Me.Controls.Add(Me.ComboBox1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If MsgBox("您真的不登录系统吗?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "退出登录系统") = MsgBoxResult.Yes Then
Application.Exit()
Else
Exit Sub
End If
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If MsgBox("您真的不登录系统吗?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "退出登录系统") = MsgBoxResult.Yes Then
e.Cancel = False
Else
e.Cancel = True
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim f2 As New Form2
User = Me.ComboBox1.Text.Trim
Password = Me.TextBox1.Text.Trim
Try
sqlstr = "select * from 管理员"
Dim da As New SqlDataAdapter(sqlstr, conn)
Dim ds As New DataSet
Dim row As DataRow
da.Fill(ds, "管理员")
Dim dt As DataTable = ds.Tables("管理员")
Dim rows As DataRow() = dt.Select("用户名='" & User & "'")
row = rows(0)
If User <> "" And Password <> "" And User = row.Item("用户名") And Password = row.Item("密码") Then
i = MsgBox("恭喜你已成功登陆", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "系统消息")
f2.Show()
Me.Finalize()
Else
i = MsgBox("密码和账号不符,请重试,并检查该账号是否存在。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "系统登录失败")
Me.TextBox1.Text = ""
End If
Static n As Integer
n = n + 1
If n = 4 Then
i = MsgBox("对不起你不是该用户!", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxHelp, "系统消息")
Close()
End If
Catch
MsgBox(Err.Description)
Exit Sub
End Try
End Sub
End Class
补充:.NET技术 , VB.NET