Results 1 to 7 of 7

Thread: about Update Button

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Location
    Malaysia
    Posts
    3

    Exclamation about Update Button

    hi, now i'm doing change password form but i try a lot of sample already but still can't work , who can show me the example.

    this is my code can u check for me thank you!!!





    Imports System.Data.SqlClient

    Public Class Form2
    Inherits System.Windows.Forms.Form

    Dim cn As New SqlConnection
    Dim da As New SqlDataAdapter
    Dim cm As New SqlCommand
    Dim ds As New DataSet
    Dim dsEmp As New DataSet
    Dim cmEmp As New SqlCommand
    Dim SQLstr As String
    Dim RowNo As Integer = 0

    Dim i As Integer
    Dim cm1 As CurrencyManager
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    cn.ConnectionString = "data source=(local);integrated security=SSPI;initial catalog=videosystem;"
    cn.Open()


    cmEmp.Connection = cn
    cmEmp.CommandText = "select * from Employees"

    da.SelectCommand = cmEmp
    da.Fill(dsEmp, "Employees")

    cm.Connection = cn
    ds.Clear()

    SQLstr = "select * from Employees where UserName ='" & str & "'"
    cm.CommandText = SQLstr
    da.SelectCommand = cm
    da.Fill(ds, "Pass")

    cm1 = Me.BindingContext(ds, "Pass")


    RefreshData()

    Dim i As Integer

    da.Fill(ds, "Employees")
    da.SelectCommand.CommandText = "select * from Employees where UserName= '" & TextBox1.Text & "'"


    da.UpdateCommand = New Data.SqlClient.SqlCommand




    End Sub
    Sub RefreshData()


    TextBox1.Text = ds.Tables("Pass").Rows(cm1.Position)(0)
    TextBox2.Text = ds.Tables("Pass").Rows(cm1.Position)(1)
    TextBox2.Focus()
    End Sub

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


    da.UpdateCommand.Connection = cn
    da.UpdateCommand.CommandText = "update Employees set Password = '" & TextBox2.Text & "'"

    Try
    da.UpdateCommand.ExecuteNonQuery()
    ds.Clear()
    da.Fill(ds, "Employees")

    Catch Ex As Exception
    End Try
    cn.Close()
    Me.Close()

    End Class

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: about Update Button

    da.UpdateCommand.CommandText = "update Employees set Password = '" & TextBox2.Text & "'"


    Are you sure you want to set everyone's password to the same thing?

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Location
    Malaysia
    Posts
    3

    no every 1 i want different password

    hi i'm new i dot net
    no i don't want the every one same password ,
    if i want different for every 1 so what are the coding i need !!!

    i think this way may work direct use sql update statement but now i still find the coding ...

    can u show me the coding ? thank you

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Just add a WHERE username = .... like in your first SQL query there.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Location
    Malaysia
    Posts
    3

    i try already

    hi i'm try already but the problem now is in the sql database table still a old data won't be change and when execute the form will display the right 1 but database table won't be change.

    when i add username = textbox2.text then all is not working but no display error.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: i try already

    Originally posted by steven2u
    hi i'm try already but the problem now is in the sql database table still a old data won't be change and when execute the form will display the right 1 but database table won't be change.

    when i add username = textbox2.text then all is not working but no display error.
    I'm sorry, but HUH?

    Can you rephrase that and try explaining again?

  7. #7
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040
    well i think the real challenge is to understand his words first

    LOL

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