没有给出一个或多个参数的值 [英] No value given for one or more parameters

查看:66
本文介绍了没有给出一个或多个参数的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这总是给我一个上面的错误请帮帮我:(

this always gives me an error like above please help me :(

Imports System.Data.OleDb
Imports System.String
' Form Load
Public Class StudInfos
    Private Sub StudInfos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CurrentRow = 0
        Con.Open()
        Dad = New OleDbDataAdapter("SELECT * FROM Students ORDER BY NickName", Con)
        Dad.Fill(Dst, "StudsInfo")
        ShowData(CurrentRow)
        Con.Close()
    End Sub
    ' To display data on form
    Private Sub ShowData(ByVal CurrentRow)
        Try
            txtNick.Text = Dst.Tables("StudsInfo").Rows(CurrentRow)("NickName")
            txtFirst.Text = Dst.Tables("StudsInfo").Rows(CurrentRow)("FirstName")
            txtLast.Text = Dst.Tables("StudsInfo").Rows(CurrentRow)("LastName")
            txtAge.Text = Dst.Tables("StudsInfo").Rows(CurrentRow)("Age")
            txtGender.Text = Dst.Tables("StudsInfo").Rows(CurrentRow)("Gender")
            txtAddress.Text = Dst.Tables("StudsInfo").Rows(CurrentRow)("Address")
            txtContact.Text = Dst.Tables("StudsInfo").Rows(CurrentRow)("ContactNo")
        Catch ex As Exception
        End Try
    End Sub

    'To select the data in NickName field
    Private Sub Nick_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtNick.GotFocus
        txtNick.SelectAll()
    End Sub

    ' To insert the record in database
    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        Dim Str As String
        Try
            Str = "insert into Students values("
            Str += txtNick.Text.Trim()
            Str += ","
            Str += """" & txtFirst.Text.Trim() & """"
            Str += ","
            Str += """" & txtLast.Text.Trim() & """"
            Str += ","
            Str += """" & txtAge.Text.Trim() & """"
            Str += ","
            Str += """" & txtGender.Text.Trim() & """"
            Str += ","
            Str += """" & txtAddress.Text.Trim() & """"
            Str += ","
            Str += txtContact.Text.Trim()
            Str += ")"
            Con.Open()
            Cmd = New OleDbCommand(Str, Con)
            Cmd.ExecuteNonQuery()
            Dst.Clear()
            Dad = New OleDbDataAdapter("SELECT * FROM Students ORDER BY NickName", Con)
            Dad.Fill(Dst, "StudsInfo")
            MsgBox("Record inserted successfully...")
            Con.Close()
        Catch ex As Exception
            MessageBox.Show("Could Not Insert Record!!!")
            MsgBox(ex.Message & " -  " & ex.Source)
            Con.Close()
        End Try
    End Sub
    ' To delete the record from database
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim Str As String
        If CheckNickName() = False Then
            MsgBox("NickName : Integer Value Required!!!")
            Exit Sub
        End If
        Try
            Str = "DELETE from Students where NickName="
            Str += txtNick.Text.Trim
            Con.Open()
            Cmd = New OleDbCommand(Str, Con)
            Cmd.ExecuteNonQuery()
            Dst.clear()
            Dad = New OleDbDataAdapter("SELECT * FROM StudsInfo ORDER BY NickName", Con)
            Dad.Fill(Dst, "StudsInfo")
            MsgBox("Record deleted successfully...")
            If CurrentRow > 0 Then
                CurrentRow -= 1
                ShowData(CurrentRow)
            End If
            Con.Close()
        Catch ex As Exception
            MessageBox.Show("Could Not delete Record!!!")
            MsgBox(ex.Message & " -  " & ex.Source)
        End Try
        Con.Close()
    End Sub
    ' To select the data in First Name Field
    Private Sub FName_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtLast.GotFocus
        txtFirst.SelectAll()
    End Sub
    ' To select the data in Last Name Field
    Private Sub LName_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFirst.GotFocus
        txtLast.SelectAll()
    End Sub
    ' To select the data in Designation Field
    Private Sub Designation_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtAddress.GotFocus
        txtAddress.SelectAll()
    End Sub
    ' To select the data in Salary Field
    Private Sub Salary_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
        txtAge.SelectAll()
    End Sub
    Private Sub Names_keypress(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAddress.KeyPress, txtAge.KeyPress, txtContact.KeyPress, txtFirst.KeyPress, txtGender.KeyPress, txtLast.KeyPress, txtNick.KeyPress
        If CheckNickName() = False Then
            MsgBox("NickName : Integer Value Required !!!")
            Exit Sub
        ElseIf CheckFName() = False Then
            MsgBox("FName : Only Characters Allowed!!!")
            Exit Sub
        ElseIf CheckLName() = False Then
            MsgBox("LName : Only Characters Allowed!!!")
            Exit Sub
        ElseIf CheckAge() = False Then
            MsgBox("age : Integer Value Required !!!")
            Exit Sub
        ElseIf CheckGender() = False Then
            MsgBox("gender : Integer  Allowed!!!")
            Exit Sub
        ElseIf CheckAddress() = False Then
            MsgBox("Address : Only Characters Allowed!!!")
            Exit Sub
        ElseIf CheckContactNo() = False Then
            MsgBox("contactno : Integer  Allowed!!!")
            Exit Sub
        End If
    End Sub
    ' To update the records in database
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

        Try
            Dim Str As String
            Str = "Update Students set NickName="
            Str += """" & txtNick.Text & """"
            Str += " where NickName="
            Str += txtNick.Text.Trim()
            Con.Open()
            Cmd = New OleDbCommand(Str, Con)
            Cmd.ExecuteNonQuery()
            Con.Close()

            Con.Open()
            Str = "update StudsInfo set FirstName="
            Str += """" & txtFirst.Text & """"
            Str += " where NickName="
            Str += txtNick.Text.Trim()
            Cmd = New OleDbCommand(Str, Con)
            Cmd.ExecuteNonQuery()
            Con.Close()

            Con.Open()
            Str = "update Students set LastName="
            Str += """" & txtLast.Text & """"
            Str += " where NickName="
            Str += txtNick.Text.Trim()
            Cmd = New OleDbCommand(Str, Con)
            Cmd.ExecuteNonQuery()
            Con.Close()

            Con.Open()
            Str = "update StudsInfo set Age="
            Str += """" & txtAge.Text & """"
            Str += " where NickName="
            Str += txtNick.Text.Trim()
            Cmd = New OleDbCommand(Str, Con)
            Cmd.ExecuteNonQuery()
            Con.Close()

            Con.Open()
            Str = "update StudsInfo set Gender="
            Str += """" & txtGender.Text & """"
            Str += " where NickName="
            Str += txtNick.Text.Trim()
            Cmd = New OleDbCommand(Str, Con)
            Cmd.ExecuteNonQuery()
            Con.Close()

            Con.Open()
            Str = "update StudsInfo set Address="
            Str += """" & txtAddress.Text & """"
            Str += " where NickName="
            Str += txtNick.Text.Trim()
            Cmd = New OleDbCommand(Str, Con)
            Cmd.ExecuteNonQuery()
            Con.Close()


            Con.Open()
            Str = "update StudsInfos set ContactNo="
            Str += """" & txtContact.Text & """"
            Str += " where NickName="
            Str += txtNick.Text.Trim()
            Cmd = New OleDbCommand(Str, Con)
            Cmd.ExecuteNonQuery()
            Con.Close()


            Dst.Clear()
            Dad = New OleDbDataAdapter("SELECT * FROM Students ORDER BY NickName", Con)
            Dad.Fill(Dst, "StudsInfo")
            MsgBox("Updated Successfully...")
        Catch ex As Exception
            MsgBox(ex.Message & "," & ex.Source)
        End Try
    End Sub
    ' To Navigate to First Record
    Private Sub First_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles First.Click
        CurrentRow = 0
        ShowData(CurrentRow)
    End Sub
    ' To Navigate to Last Record
    Private Sub Previous_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Previous.Click
        If CurrentRow <> 0 Then
            CurrentRow -= 1
            ShowData(CurrentRow)
        Else
            MsgBox("First Record is Reached!!!")
        End If
    End Sub
    ' To Navigate to Next Record
    Private Sub Forward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Forward.Click
        If CurrentRow = Dst.Tables("StudsInfo").Rows.Count - 1 Then
            MsgBox("Last Record is Reached!!!")
        Else
            CurrentRow += 1
            ShowData(CurrentRow)
        End If
    End Sub
    ' To Navigate to Last Record
    Private Sub Last_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Last.Click
        CurrentRow = Dst.Tables("StudsInfo").Rows.Count - 1
        ShowData(CurrentRow)
    End Sub
    ' To check the data in NickName field : whether String or not 
    Private Function CheckNickName()
        Try
            If txtNick.Text = "" Or ValNickNameateString(txtNick.Text) = False Then
                ShowData(CurrentRow)
                txtNick.Focus()
                Return False
            End If
        Catch ex As Exception
        End Try
        Return True
    End Function

    ' To check the data in Age field : whether numeric or not 
    Private Function CheckAge()
        Try
            If IsNumeric(txtAge.Text) = False Then
                ShowData(CurrentRow)
                txtAge.Focus()
                Return False
            End If
        Catch ex As Exception
        End Try
        Return True
    End Function
    ' To check the data in Contactno field : whether numeric or not 
    Private Function CheckContactNo()
        Try
            If IsNumeric(txtContact.Text) = False Then
                ShowData(CurrentRow)
                txtContact.Focus()
                Return False
            End If
        Catch ex As Exception
        End Try
        Return True
    End Function

    ' To check the data in First Name Field : whether a string or not

    Private Function CheckFName()
        Try
            If txtFirst.Text = "" Or ValNickNameateString(txtFirst.Text) = False Then
                ShowData(CurrentRow)
                txtFirst.Focus()
                Return False
            End If
        Catch ex As Exception
        End Try
        Return True
    End Function
    ' To check the data in Last Name Field : whether a string or not
    Private Function CheckLName()
        Try
            If txtLast.Text = "" Or ValNickNameateString(txtLast.Text) = False Then
                ShowData(CurrentRow)
                txtLast.Focus()
                Return False
            End If
        Catch ex As Exception
        End Try
        Return True
    End Function
    ' To check the data in address Field : whether a string or not
    Private Function CheckAddress()
        Try
            If txtAddress.Text = "" Or ValNickNameateString(txtAddress.Text) = False Then
                ShowData(CurrentRow)
                txtAddress.Focus()
                Return False
            End If
        Catch ex As Exception
        End Try
        Return True
    End Function
    Private Function CheckGender()
        Try
            If txtGender.Text = "" Or ValNickNameateString(txtGender.Text) = False Then
                ShowData(CurrentRow)
                txtGender.Focus()
                Return False
            End If
        Catch ex As Exception
        End Try
        Return True
    End Function
    ' To check the string for numeric values
    Private Function ValNickNameateString(ByVal Str)
        Dim i As Integer
        Dim ch As Char
        i = 0
        While i < Str.Length()
            ch = Str.Chars(i)
            If IsNumeric(ch) = True Then
                Return False
            End If
            i += 1
        End While
        Return True
    End Function

    ' To check whether NickName exist in database
    Private Function IsNickNameExist()
        Dim Str, Str1 As String
        Dim i As Integer
        Str = txtNick.Text
        i = 0
        While i <> Dst.Tables("StudsInfo").rows.count
            Str1 = Dst.Tables("StudsInfo").Rows(i)("NickName")
            If Str = Str1 Then
                Return True
            End If
            i += 1
        End While
        Return False
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ViewStudents.Show()
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        ' To clear all fields : NickName, First Name, Last Name
        txtNick.Text = ""
        txtFirst.Text = ""
        txtLast.Text = ""
        txtAge.Text = ""
        txtAddress.Text = ""
        txtGender.Text = ""
        txtContact.Text = ""
    End Sub
End Class

推荐答案

Many possibilities. Make sure you’re passing right values to query.

Case 1

Many possibilities. Make sure you're passing right values to query.
Case 1
Str = "insert into Students values("
Str += txtNick.Text.Trim()
Str += ","
Str += """" & txtFirst.Text.Trim() & """"
Str += ","
Str += """" & txtLast.Text.Trim() & """"
Str += ","
Str += """" & txtAge.Text.Trim() & """"
Str += ","
Str += """" & txtGender.Text.Trim() & """"
Str += ","
Str += """" & txtAddress.Text.Trim() & """"
Str += ","
Str += txtContact.Text.Trim()
Str += ")"

If you miss any value, this query’d fail. Say you’re passing blank values, you’ll get below query which is bad one.

If you miss any value, this query'd fail. Say you're passing blank values, you'll get below query which is bad one.

insert into Students values(,'','','','','')

Case 2

Case 2

Str = "DELETE from Students where NickName="
Str += txtNick.Text.Trim

Same as above, if you pass blank value, you’ll get below query which won’t work.

Same as above, if you pass blank value, you'll get below query which won't work.

DELETE from Students where NickName=



Case N

Samething goes for all other UPDATE queries. If you pass blankstring(’’) when your validation fails, that query won’t work.


Case N
Samething goes for all other UPDATE queries. If you pass blankstring('') when your validation fails, that query won't work.


这篇关于没有给出一个或多个参数的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆