check if user-id exists then edit

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • crzyice
    New Member
    • May 2012
    • 4

    check if user-id exists then edit

    Greetings,
    im a beginner in vb.net and im trying to make a survey program(which consists of radiobuttons- poor,fair,good, verygood,excell ent) that when a user inputs its user-id. the program will check the database whether the user-id has been entered before or not. if existing, the user may edit the original/existing survey record. im using MS SQL as a back-end. and also, i was asked to use 1 form only.

    i was just wondering if you guys can help me out by showing some examples of your way of programming it, 'cause honestly, i dont have that much idea yet when it comes to vb.net.

    Thank you in advance.
  • Pegasus40218
    New Member
    • Apr 2010
    • 4

    #2
    Are you writing an ASP.Net application with VB.Net on the back-end or are you writing a VB.Net Windows Forms application?

    Comment

    • crzyice
      New Member
      • May 2012
      • 4

      #3
      im writing asp.net with vb.net sir. sorry, i got lost with my message. but the good news is, i finally manage to check user-id if it exists sir. i used read.item. but there's just another one problem. i cant call the sub saverec() which allows the user to save unentered value.

      here's my code sir :
      Code:
      Protected Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
      
              Dim con As New SqlConnection
              Dim cmd As New SqlCommand()
              con.ConnectionString = "Data Source = MARITES; Initial Catalog = dbClientFeedBack; Persist Security Info = True; User ID = sa; Password = sa;"
              con.Open()
              cmd.Connection = con
      
              Dim sql As String
              sql = ("SELECT * FROM tblFeedBackPK WHERE ORNum ='" & txtORNum.Text & "'")
              cmd.CommandText = sql
              Dim read As SqlDataReader = cmd.ExecuteReader
              While read.Read
      
                  
                  
                  If read.Item("ORNum").ToString = txtORNum.Text Then
                      Dim msgedit As DialogResult = MsgBox("OR NUMBER ALREADY EXIST, Do you want to edit?", MsgBoxStyle.YesNo)
                      If msgedit = Windows.Forms.DialogResult.Yes Then
                          calling()
      
                      Else
                          txtORNum.Text = ""
                          Page.Form.DefaultFocus = txtORNum.ClientID()
                          button1.Visible = False
                          Button2.Visible = True
                      End If
                      
                  ElseIf read.HasRows = 0 Then
                      saverec()
                  End If
      
              End While
              con.Close()
      
      
      
          End Sub
      here is my saving() sub

      Code:
      Public Sub saverec()
              Dim con As New SqlConnection
              Dim cmd As New SqlCommand()
              con.ConnectionString = "Data Source = MARITES; Initial Catalog = dbClientFeedBack; Persist Security Info = True; User ID = sa; Password = sa;"
              cmd.Connection = con
              con.Open()
              cmd.CommandText = "INSERT INTO tblFeedBackPK(ORNum,poorAvail,poorPrice,poorTransc,poorStore,poorCourt,poorAccess,fairAvail,fairPrice,fairTransc,fairStore,fairCourt,fairAccess,goodAvail,goodPrice,goodTransc,goodStore,goodCourt,goodAccess,vgAvail,vgPrice,vgTransc,vgStore,vgCourt,vgAccess,excellentAvail,excellentPrice,excellentTransc,excellentStore,excellentCourt,excellentAccess) VALUES('" & txtORNum.Text & "','" & poor1.Checked & "','" & poor2.Checked & "','" & poor3.Checked & "','" & poor4.Checked & "','" & poor5.Checked & "','" & poor6.Checked & "','" & fair1.Checked & "','" & fair2.Checked & "','" & fair3.Checked & "','" & fair4.Checked & "','" & fair5.Checked & "','" & fair6.Checked & "','" & good1.Checked & "','" & good2.Checked & "','" & good3.Checked & "','" & good4.Checked & "','" & good5.Checked & "','" & good6.Checked & "','" & verygood1.Checked & "','" & verygood2.Checked & "','" & verygood3.Checked & "','" & verygood4.Checked & "','" & verygood5.Checked & "','" & verygood6.Checked & "','" & excellent1.Checked & "','" & excellent2.Checked & "','" & excellent3.Checked & "','" & excellent4.Checked & "','" & excellent5.Checked & "','" & excellent6.Checked & "')"
              cmd.ExecuteNonQuery()
              MsgBox("SUCCESS")
              button1.Visible = True
              Button2.Visible = False
      
              clearing()
      
          End Sub

      Comment

      • crzyice
        New Member
        • May 2012
        • 4

        #4
        every time i click the button save (which is not an existing number), nothing happens and and the button just disappears. but when an existing value was entered. the msg prompts asking the user if he wants to edit. after edit was done, still the button just disappears upon saving and nothing happens.

        sorry for bothering you pegasus.
        any help will be appreciated :)

        Comment

        • crzyice
          New Member
          • May 2012
          • 4

          #5
          hey peg!

          Originally posted by Pegasus40218
          Are you writing an ASP.Net application with VB.Net on the back-end or are you writing a VB.Net Windows Forms application?
          WOOHOO! nvm pegs i finally managed to execute it. i removed sub saving() inside the while loop. sorry for bothering you. thank you too :) keepsafe.
          God bless :)

          Comment

          Working...