Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i've a problem with insert and update button function,error in line
Quote:
If uniqueNamaModis(txtNamaModis.Text) = True Then
i use vb.net webforms. please help me

What I have tried:

myfunction below:
VB
Public Function uniqueNamaModis() As Boolean
        Dim nmodis As String
        Dim query As String = "select count(namamodis) as namamodis from master_planogram where namamodis='" + txtNamaModis.Text & "'"
        Dim sqlCon As New MySqlConnection(ObjFungsi.ConDataProduction)
        sqlCon.Open()
        Dim cmd As New MySqlCommand(query, sqlCon)
        Dim dr As MySqlDataReader
        dr = cmd.ExecuteReader()

        While dr.Read()

            Try
                nmodis = dr("namamodis").ToString()
                Return (nmodis <> "0")

                If nmodis <> "0" Then
                    Return False
                End If

            Catch e As Exception
                Dim message As String = "Error"
                message += e.Message
            Finally
                dr.Close()
                sqlCon.Close()
            End Try
        End While

        Return True
    End Function


my button below:
VB
Protected Sub btnEditSimpanSelected_Click(sender As Object, e As EventArgs)
        Dim sqlCon As New MySqlConnection(ObjFungsi.ConDataProduction)
        sqlCon.Open()
        Dim cmd As MySqlCommand = sqlCon.CreateCommand()
        cmd.CommandType = CommandType.Text

        If uniqueNamaModis(txtNamaModis.Text) = True Then
            cmd.CommandText = "UPDATE master_planogram Set namamodis='" & txtNamaModis.Text & "'"
            cmd.CommandText += " , namaplu='" + txtPlu2.Text & "', deskripsiplu='" + txtDesc2.Text & "'"
            cmd.CommandText += " , kodetoko='" + txtSrcByKdtk.Text & "', namatoko='" + txtSrcByNmtk.Text & "', cabang='" + txtSrcByKdcab.Text & "'"
            cmd.CommandText += " where namamodis='" + txtNamaModis.Text & "'"
        Else
            cmd.CommandText = "INSERT INTO master_planogram values('" & txtNamaModis.Text & "', '" + txtPlu2.Text & "', '" + txtDesc2.Text & "'"
            cmd.CommandText += " , '" + txtSrcByKdtk.Text & "', '" + txtSrcByNmtk.Text & "', '" + txtSrcByKdcab.Text & "')"
        End If
        cmd.ExecuteNonQuery()
        sqlCon.Close()
    End Sub
Posted
Updated 23-Jul-20 18:36pm
Comments

1 solution

Your method definition is:
Public Function uniqueNamaModis() As Boolean

=> It has no parameters defined to be taken as input. It's uniqueNamaModis()

But, while using the method, you are passing a parameter, thus an error.
If uniqueNamaModis(txtNamaModis.Text) = True Then

Remove string parameter from caller or add that as expected parameter in the method definition.
If uniqueNamaModis() = True Then

OR
Public Function uniqueNamaModis(someText as String) As Boolean
 
Share this answer
 
Comments
SDK Channel 24-Jul-20 2:34am    
its work! thanks a lot sir.

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