Sebastian_1 0 Newbie Poster

I have a login form that asks for credentials for access to select areas of a large app I wrote.
I am trying to add a form to allow for password changes via that app instead of me having to update the SQL DB manually.

DB has 1 table called "Code" with 2 colums "CodeLvl" and "CmdCode"

I want the form to select the entry for CodeLvl and CmdCode where they match and to then update just CmdCode.

When I test the new form it outputs Code Changed, however it does not actually update the DB.

Private Sub OK_Click_1(sender As Object, e As EventArgs) Handles OK.Click
        Dim cn As New SqlConnection()
        Dim CmdDataSet As New DataSet()
        Dim command As New SqlClient.SqlCommand
        Dim da As SqlDataAdapter
        Dim DAUpdateCmd As SqlCommand
        cn.ConnectionString = ("Data Source=DULLAHANII\DRAGONNET;Initial Catalog=LCARS;Persist Security Info=True" & _
          ";User ID=**;Password=******")
        command.CommandText = "SELECT * FROM Code WHERE CodeLvl='" & codelvl.Text & "';"
        cn.Open()
        da = New SqlDataAdapter("select * from Code", cn)

            DAUpdateCmd = New SqlCommand("Update Code set CmdCode = commandcode.text where CodeLvl = codelvl.text", da.SelectCommand.Connection)


            'Create and append the parameters for the Update command.

        DAUpdateCmd.Parameters.Add(New SqlParameter("commandcode.text", SqlDbType.VarChar))
        DAUpdateCmd.Parameters("commandcode.text").SourceVersion = DataRowVersion.Current
        DAUpdateCmd.Parameters("commandcode.text").SourceColumn = "CmdCode"

        'Assign the SqlCommand to the UpdateCommand property of the SqlDataAdapter.
            da.UpdateCommand = DAUpdateCmd

        da.Fill(CmdDataSet, "Code")

        Console.WriteLine("Command Code before Update : " & CmdDataSet.Tables("Code").Rows(0)("CmdCode"))

        Console.WriteLine("Code updated successfully")

            cn.Close()
            Console.ReadLine()
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.