Click here to Skip to main content
16,006,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
<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>


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
Posted

Its is complaining because the parameter you pass to the Fill method is not an instance of a DataTable.
Try changing this line:
VB
Dim dt As DataTable
To this:
VB
Dim dt As New DataTable()
 
Share this answer
 
Comments
Simon_Whale 19-Feb-12 5:54am    
Nice spot +5
Also the following parts of your code need to be removed as they are doing nothing

VB
cmd = New SqlCommand(str, con)
'
'do other stuff
'
cmd.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[^]
 
Share this answer
 
Your sql statement is not good, please change it to:
VB
str = "select * from Adminlogin where Username='"& UnameTextBox.Text &"' AND Password= ' " & UPassword.Text & " ' "
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900