CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2013
    Posts
    4

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: No value given for one or more required parameters in VB.Net

    What is dt supposed to be?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Mar 2013
    Posts
    4

    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





    Quote Originally Posted by sujit_bh2 View Post
    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

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.

  5. #5
    Join Date
    Mar 2013
    Posts
    4

    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

  6. #6
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.

  7. #7
    Join Date
    Mar 2013
    Posts
    4

    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

  8. #8
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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
  •  





Click Here to Expand Forum to Full Width

Featured