-
March 28th, 2013, 01:39 PM
#1
No value given for one or more required parameters in VB.Net
Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\TEST\VB.net TEST\WindowsApplication1\WindowsApplication1\SKB.MDB"
Dim Username As String
Dim Password As String
Dim con As OleDbConnection = New OleDbConnection(strConnection)
con.Open()
da = New OleDbDataAdapter("select Username AND Passowrd FROM UserAccount ORDER BY Username", con)
Textbox1.Text = da.Fill(dt)
TextBox2.Text = da.Fill(dt)
' Textbox1.Text = "Username"
'TextBox2.Text = "Password"
If Textbox1.Text = Username And TextBox2.Text = Password Then
Show(MDIParent1)
Else
MsgBox("Please Enter the appropriate Username and Password", MsgBoxStyle.OkOnly)
End If
con.Close()
I mentioned the Code above and getting an Error in "Textbox1.Text = da.Fill(dt)
TextBox2.Text = da.Fill(dt)
Please help me
-
March 28th, 2013, 10:17 PM
#2
Re: No value given for one or more required parameters in VB.Net
What is dt supposed to be?
-
March 28th, 2013, 10:26 PM
#3
Re: No value given for one or more required parameters in VB.Net
Public Class Login
Dim con As New OleDbConnection
Dim ds As New DataSet
Dim dt As New DataTable
Dim da As New OleDbDataAdapter
Dim skb As New DataSet
Originally Posted by sujit_bh2
Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\TEST\VB.net TEST\WindowsApplication1\WindowsApplication1\SKB.MDB"
Dim Username As String
Dim Password As String
Dim con As OleDbConnection = New OleDbConnection(strConnection)
con.Open()
da = New OleDbDataAdapter("select Username AND Passowrd FROM UserAccount ORDER BY Username", con)
Textbox1.Text = da.Fill(dt)
TextBox2.Text = da.Fill(dt)
' Textbox1.Text = "Username"
'TextBox2.Text = "Password"
If Textbox1.Text = Username And TextBox2.Text = Password Then
Show(MDIParent1)
Else
MsgBox("Please Enter the appropriate Username and Password", MsgBoxStyle.OkOnly)
End If
con.Close()
I mentioned the Code above and getting an Error in "Textbox1.Text = da.Fill(dt)
TextBox2.Text = da.Fill(dt)
Please help me
As you have asked what "dt" has to do in the code "dt" has been decaied as the DataTable
-
March 29th, 2013, 07:55 AM
#4
Re: No value given for one or more required parameters in VB.Net
Password is a reserved word and should not be used as a field name. If it must be used then you need to bracket it in your sql statements i.e. [Password]
You are calling fill twice and trying to set the text object of the text boxes there.
You shoudl probably be using a data reader instead and using a where clause in your sql statement so only one record is returned, or better still you don;t even need a reader just query the db using execute scalar using the username as the where clause and return the password then test to see if it matches what was entered by the user.
Last edited by DataMiser; March 29th, 2013 at 07:59 AM.
Always use [code][/code] tags when posting code.
-
March 29th, 2013, 11:01 AM
#5
Re: No value given for one or more required parameters in VB.Net
Can you please let me know in the code where should I make changes
-
March 29th, 2013, 03:39 PM
#6
Re: No value given for one or more required parameters in VB.Net
Here is an example for a login using a datareader that I was playing around with a while back
Code:
Try
Using CN As New SqlConnection(TCData.ConnectionString)
CN.Open()
Using Cmd As SqlCommand = CN.CreateCommand
Cmd.CommandText = "Select [password],AccessLevel from tblusers where userid=@UserID"
Cmd.Parameters.AddWithValue("@UserID", UsernameTextBox.Text)
Using dReader As SqlDataReader = Cmd.ExecuteReader
If dReader.HasRows Then
dReader.Read()
If dReader("password") = PasswordTextBox.Text Then
UserLevel = dReader("AccessLevel")
Me.DialogResult = Windows.Forms.DialogResult.OK
Me.Hide()
Else
UserLevel = ""
PasswordTextBox.Text = ""
MessageBox.Show("Invalid Password", "Denied", MessageBoxButtons.OK, MessageBoxIcon.Error)
PasswordTextBox.Focus()
End If
Else
UserLevel = ""
UsernameTextBox.Text = ""
MessageBox.Show("Invalid UserID", "Denied", MessageBoxButtons.OK, MessageBoxIcon.Error)
UsernameTextBox.Focus()
End If
End Using
End Using
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK)
End Try
Note this code uses SQl Server so the connection and command objects will be different but the part in red is what you should pay attention to.
Always use [code][/code] tags when posting code.
-
March 30th, 2013, 01:26 AM
#7
Re: No value given for one or more required parameters in VB.Net
Sir,
As you can in my codes that I have used the OLEDB than SQL. How do I make changes in that scenario to make the module run
-
March 30th, 2013, 08:43 AM
#8
Re: No value given for one or more required parameters in VB.Net
Like I said the part in red is the important part. You are using the OLEDB connection so you would use an OLEDBCommand rather than a SQLCommand the part in red would be the same using your field names of course..
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|