By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,990 Members | 2,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,990 IT Pros & Developers. It's quick & easy.

check if user-id exists then edit

P: 4
Greetings,
im a beginner in vb.net and im trying to make a survey program(which consists of radiobuttons- poor,fair,good,verygood,excellent) 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.
May 23 '12 #1

✓ answered 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?

Share this Question
Share on Google+
4 Replies


P: 4
Are you writing an ASP.Net application with VB.Net on the back-end or are you writing a VB.Net Windows Forms application?
May 24 '12 #2

P: 4
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 :
Expand|Select|Wrap|Line Numbers
  1. Protected Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  2.  
  3.         Dim con As New SqlConnection
  4.         Dim cmd As New SqlCommand()
  5.         con.ConnectionString = "Data Source = MARITES; Initial Catalog = dbClientFeedBack; Persist Security Info = True; User ID = sa; Password = sa;"
  6.         con.Open()
  7.         cmd.Connection = con
  8.  
  9.         Dim sql As String
  10.         sql = ("SELECT * FROM tblFeedBackPK WHERE ORNum ='" & txtORNum.Text & "'")
  11.         cmd.CommandText = sql
  12.         Dim read As SqlDataReader = cmd.ExecuteReader
  13.         While read.Read
  14.  
  15.  
  16.  
  17.             If read.Item("ORNum").ToString = txtORNum.Text Then
  18.                 Dim msgedit As DialogResult = MsgBox("OR NUMBER ALREADY EXIST, Do you want to edit?", MsgBoxStyle.YesNo)
  19.                 If msgedit = Windows.Forms.DialogResult.Yes Then
  20.                     calling()
  21.  
  22.                 Else
  23.                     txtORNum.Text = ""
  24.                     Page.Form.DefaultFocus = txtORNum.ClientID()
  25.                     button1.Visible = False
  26.                     Button2.Visible = True
  27.                 End If
  28.  
  29.             ElseIf read.HasRows = 0 Then
  30.                 saverec()
  31.             End If
  32.  
  33.         End While
  34.         con.Close()
  35.  
  36.  
  37.  
  38.     End Sub
  39.  
  40.  
here is my saving() sub

Expand|Select|Wrap|Line Numbers
  1. Public Sub saverec()
  2.         Dim con As New SqlConnection
  3.         Dim cmd As New SqlCommand()
  4.         con.ConnectionString = "Data Source = MARITES; Initial Catalog = dbClientFeedBack; Persist Security Info = True; User ID = sa; Password = sa;"
  5.         cmd.Connection = con
  6.         con.Open()
  7.         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 & "')"
  8.         cmd.ExecuteNonQuery()
  9.         MsgBox("SUCCESS")
  10.         button1.Visible = True
  11.         Button2.Visible = False
  12.  
  13.         clearing()
  14.  
  15.     End Sub
May 25 '12 #3

P: 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 :)
May 25 '12 #4

P: 4
@Pegasus40218
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 :)
May 25 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.