vb.net中的sql connetion错误消息值不能为null [英] sql connetion in vb.net error message values can't null
问题描述
表名称:Adminlogin
用户名密码
拉维123
拉梅什456
表格定义:
列名称数据类型
用户名varchar(25)null
密码nvarchar(25)null
我的源代码:
Table Name: Adminlogin
Username Password
Ravi 123
Ramesh 456
Table Definition:
column name Datatype
Username varchar(25) null
Password nvarchar(25)null
My source code:
<pre lang="vb">
Dim con As New SqlConnection("Data Source=D729Z\SQLEXPRESS;Initial Catalog=Franchise;Integrated Security=True")
Dim da As New SqlDataAdapter
Dim ds As New SqlDataSource
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
Dim dt As DataTable
Dim str As String
str = "select * from Adminlogin where Username='"& UnameTextBox.Text &"', ' " & UPassword.Text & " ' "
da = New SqlDataAdapter(str, con)
cmd = New SqlCommand(str, con)
da.Fill(dt)
If dt.Rows.Count < > 0 Then
Response.Redirect("SelectBranch.aspx")
Else
MsgBox(" Username and password invalided ")
End If
cmd.ExecuteNonQuery()
con.Close()</pre>
运行时错误消息:
da.fill(dt)是错误点
值不能为null;参数名称:dataTable
我如何解决此问题,请发送相关示例作为相关教程
Run time Error message:
da.fill(dt) is Error point
Value can''t be null; Parameter name:dataTable
how can i solve this problem, send related examples are related tutorials
推荐答案
它抱怨,因为您传递给Fill方法的参数是不是DataTable的实例.
尝试更改此行:
Its is complaining because the parameter you pass to the Fill method is not an instance of a DataTable.
Try changing this line:
Dim dt As DataTable
对此:
Dim dt As New DataTable()
还需要删除代码的以下部分,因为它们什么都不做
Also the following parts of your code need to be removed as they are doing nothing
cmd = New SqlCommand(str, con)
'
'do other stuff
'
cmd.ExecuteNonQuery()
ExecuteNonQuery
用于要执行不返回结果集但返回受影响的行数"的查询integer
进一步阅读 SqlCommand.ExecuteNonQuery方法 [ ^ ]
ExecuteNonQuery
is used when you want to execute a query that doesn''t return a result set, but rather returns a "number of rows" affected integer
Further reading SqlCommand.ExecuteNonQuery Method[^]
您的sql语句不好,请将其更改为:
Your sql statement is not good, please change it to:
str = "select * from Adminlogin where Username='"& UnameTextBox.Text &"' AND Password= ' " & UPassword.Text & " ' "
这篇关于vb.net中的sql connetion错误消息值不能为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!