473,395 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Updating a value if cell is DBNull

33
hi, i want to know how to implement this one, im trying to do a login page in vb.net and after 3 consecutive login attempts, the username will be locked and will not be able to login to the system.

inside my database, i have three columns, the username, password, and loginattempst column.

Expand|Select|Wrap|Line Numbers
  1. Dim cmd As New SqlCommand("select * from users where username=@username", conn)
  2. cmd.Parameters.AddWithValue("@username", TextBox1.Text)
so the above code selects the username from my database, but my problem is how to read the item on the loginattempts column. I heard about data reader but i dont know yet how to use it properly. This is actually code using datareader on my form

Expand|Select|Wrap|Line Numbers
  1.         Using conn As New SqlConnection(constring)
  2.             Try
  3.                 conn.Open()
  4.                 Dim cmd As New SqlCommand("select * from users where username=@username and password=@password", conn)
  5.                 cmd.Parameters.AddWithValue("@username", TextBox1.Text.ToString)
  6.                 cmd.Parameters.AddWithValue("@password", TextBox2.Text.ToString)
  7.                 Dim dr = cmd.ExecuteReader
  8.                 If dr.HasRows Then
  9.                     Form2.Show()
  10.                     Me.Hide()
  11.                 Else
  12.                     MessageBox.Show("Put some error messages here")
  13.                 End If
  14.  
  15.             Catch ex As Exception
  16.                 'do something here
  17.             End Try
  18.  
  19.  
Oct 30 '14 #1
1 1278
Frinavale
9,735 Expert Mod 8TB
This particular rule is going to require more design than you currently have.

Right now you are selecting from your users table where username=@username and if one is returned you show Form2.

If there is no row with the user name, then the user can't log in and they failed their log-in attempt.

In this case you need to somehow track the number of failed log-in attempts.

If you are planning on storing the failed login attempts in the user's row and there is no row found that matches the user, then how are you going to retrieve the amount of failed log-in attempts for the user?

In your case I would set counter in memory (instead of in the database) and once it gets to 3 the application would close.

However, that would not prevent the user from opening the application and attempting 3 more times to log in.

So, you are going to have to design a solution that takes all of these factors into consideration.

-Frinny
Oct 30 '14 #2

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

Similar topics

1
by: Neo | last post by:
I have a table Contacts with a field "Male" which is of type Bit (SQL Server). I've got two radio buttons in a panel, & one of them is bound to the above field, (so that one can see if the contact...
2
by: Neo | last post by:
I have a table Contacts with a field "Male" which is of type Bit (SQL Server). I've got two radio buttons in a panel, & one of them is bound to the above field, (so that one can see if the...
3
by: Brett Romero | last post by:
Is there a way to update data in a DataTable cell? I have column dates that are string type. I want to add another column to this table: dt.Columns.Add(new DataColumn("Datecolumn2",...
1
by: JaxDawg | last post by:
Hey folks... I've got an interesting problem. I'm updating and displaying an excel spreadsheet (using com) from a php file. Works great in the debugger (PhpEd 4.6), but not otherwise. I assume...
1
by: PawelR | last post by:
Hi Group, In my application I have DataTable which is displayed in DataGridView via DataView: DataView myView = new DataView(myTable); myDataGridView.DataSource = myView; One column im...
10
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I understand how to connect a SqlDataSource to a GridView and have a nice data-connected, paginated web page generated with virtually no coding. Starting from that base, I would like to add an...
2
by: HenrikRinder | last post by:
This is a silly question, but now I have spent hours trying to figure it out. Thus, asking this forum: Our application GUI has a .NET PropertyGrid. Our customers don't find it intuitive to...
3
by: shlabadoo | last post by:
Hello, I searched for quite a while for an answer to this, but with no joy. All the answeres seem to be how to deal with getting a DBNull value out of a database, not to put it in . Perhaps I am...
0
by: Ben | last post by:
Hi, With this code, when i click on Update button, the value updated of field "wa" in the table is NULL.The update of the other field (not in a DD) works good. It seems that the selectedvalue...
0
by: loginarpit | last post by:
I am dynamically creating a row of elements including a HiddenField. In a client-side function I am updating the value of this HiddenField. its ok till now. Now a button click causes a postback...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.