m_dal.DataSetFill(sql),提示参数太多。
请教老师们m_dal.DataSetFill(sql),提示参数太多。
引用类
Public Class ClassDB
Public cn As System.Data.SqlClient.SqlConnection
Public da As System.Data.SqlClient.SqlDataAdapter
Public ds As New DataSet
Public dt As New DataTable
Public cmd As System.Data.SqlClient.SqlCommand
'****************************************************************************************
'连接数据库
Public Function ConnectionOpen() As Boolean 'ByVal server As String, ByVal DBName As String, ByVal uid As String, ByVal pwd As String
Dim cnstr As String = "Persist Security Info=False;" _
& "Server=" & Server & ";" _
& "Database=" & DBName & ";" _
& "User ID=" & DBUser & ";" _
& "Password=" & Pwd
cn = New System.Data.SqlClient.SqlConnection(cnstr)
Try
cn.Open()
Catch ex As System.Data.SqlClient.SqlException
MsgBox(ex.Message.ToString())
End Try
End Function
'断开数据库的连接
Public Function ConnectionClose() As Boolean
Try
cn.Close()
Catch ex As System.Data.SqlClient.SqlException
MsgBox(ex.Message.ToString())
End Try
End Function
'插入记录、删除记录、更新记录到指定的数据库->数据表
Public Function InsertDelUpdateRecord() As Boolean 'ByVal cmdText As String
Try
cmd = New System.Data.SqlClient.SqlCommand(cmdText, cn) '指定sql命令及该命令用于哪一个数据库连接
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try
End Function
'填充数据集,他会根据cmdtext参数说指定的查询返回数据库里特定的表
Public Function DataSetFill() As Boolean 'ByVal cmdText As String, ByVal tabName As String
Try
cmd = New System.Data.SqlClient.SqlCommand(cmdText, cn) '指定sql查询命令及该命令用于哪一个数据库连接
da = New System.Data.SqlClient.SqlDataAdapter(cmd)
da.Fill(ds, tabName) '表名可以映射为数据库中实际的表名称,但是他和数据库实际的表名称不是一回事
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try
End Function
'调用存储过程
Public Function ExecProc() As Boolean 'ByVal procName As String, ByVal tabName As String
Try
cmd = New System.Data.SqlClient.SqlCommand(procName, cn)
cmd.CommandType = CommandType.StoredProcedure
da = New System.Data.SqlClient.SqlDataAdapter(cmd)
da.Fill(ds, tabName)
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try
End Function
'这个基本不用,因为可以直接通过ds来调用
Public Function DataTable() As Boolean 'ByVal index As Integer
Try
dt = ds.Tables(index)
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try
End Function
'这个基本不用,因为可以直接通过ds来调用
Public Function DataTableFill() As Boolean 'ByVal name As String
Try
dt = ds.Tables(name)
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try
End Function
'释放资源
Public Function DBDispos() As Boolean
Try
cn.Dispose()
'da.Dispose()
ds.Dispose()
dt.Dispose()
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try
End Function
End Class
添加全局变量
Module ModuleGvar
'定义全局变量服务器:IP、数据库名称、登陆名称、登录密码
Public Server As String, DBName As String, DBUser As String, Pwd As String
'查询指定数据库、数据表名、xx、
Public cmdText As String, tabName As String, procName As String, index As String, name As String, m_dal As New ClassDB
End Module
窗体代码
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Server = "127.0.0.1"
DBName ="asdf"
DBUser = "saas"
Pwd = "asas"
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = ChrW(13) Then
Me.Button1.PerformClick()
End If
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If e.KeyChar = ChrW(13) Then
Me.Button1.PerformClick()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.TextBox1.Text = "" Then
MsgBox("请输入用户名")
Me.TextBox1.Focus()
Exit Sub
End If
If Me.TextBox2.Text = "" Then
MsgBox("请输入密码")
Me.TextBox2.Focus()
Exit Sub
End If
Dim datable As New DataTable
Dim psw As String
Dim sql As String
sql = "select * from 人员信息 where id='" & Me.TextBox1.Text & "'"
m_dal.DataSetFill(sql)本句报错“Public Function DataSetFill() As Boolean参数太多”
datable = m_dal.ds.Tables("姓名")
If datable.Rows.Count = 0 Then
MessageBox.Show("用户不存在")
Else
psw = datable.Rows(0).Item("psw")
If psw <> Me.TextBox2.Text Then
MessageBox.Show("密码错误")
Else
MessageBox.Show("登陆成功")
Me.Hide()
Form2.Show()
End If
End If
End Sub
End Class
[解决办法]
你没有带参数的DataSetFill函数定义
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/