Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,381 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,315 people online right now. Registration is fast and FREE... Join Now!




login form with text box in vb.net

 
Reply to this topicStart new topic

login form with text box in vb.net, login form with text box

nirmala82
14 Sep, 2008 - 05:54 PM
Post #1

New D.I.C Head
*

Joined: 12 Sep, 2008
Posts: 9

hi frends,its bit urgent for me,can anyone find me coding of the below mentioned requirement,thank frens in advance those who r helping me...


need to give one number in textbox click login button,the text box value shld be chekd with the database table(borrower),if borrowernumber(one of the field in borrowertable) has the same value,if so, automatically go to next for which shld display all the information of thhe borrwers in datagrid with a label text visible at runtime...thanks
in form1:

vb

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myAdapter As New OdbcDataAdapter
Dim query = "SELECT cardnumber FROM borrowers Where cardnumber='" & txtcardnumber.Text & "'"

Dim myCommand As OdbcCommand = New Odbc.OdbcCommand(query, conOdbc)
Dim dr As OdbcDataReader
dr = myCommand.ExecuteReader


If dr.HasRows = True Then

MessageBox.Show("Login Successful", "Login", MessageBoxButtons.OK)


MsgBox("Please Wait......")

Dim issues As New Testforissues
issues.Show()
Else
MsgBox("Invalid Login details!!!", MsgBoxStyle.Exclamation)
Application.Exit()

End If
'conOdbc.Close()


End Sub
Private Sub connectDatabase()
Dim conStr As String = "DRIVER={MySQL ODBC 3.51 Driver};Server=localhost;PORT=3306;DATABASE=db229-152926;User=;PWD=;option=3;"
Try
conOdbc.ConnectionString = conStr
conOdbc.Open()
MsgBox("Connection opened Successfully")


Catch ex As Exception

MsgBox(ex.Message)



End Try
End Sub

Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
connectDatabase()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Application.Exit()
End Sub

i form2 to display the details of borrower from the value given by textbox1.text in form 1

for that
borrowerdetails_load 'form load event

cmd.Connection = conOdbc
If conOdbc.State = ConnectionState.Closed Then
conOdbc.Open()
End If
Try
cmd.CommandText = "select * from borrowers where cardnumber='" &form1.txtcardnumber.text'&"
cmd.ExecuteNonQuery()
Dim ds As New DataSet("borrower")
Dim da As New OdbcDataAdapter("SELECT * FROM borrowers where cardnumber='" &form1.txtcardnumber.text'&"
", conOdbc)
da.Fill(ds, "borrowers")
DataGrid1.DataSource = ds.DefaultViewManager
Catch ex As Exception
MsgBox(ex.Message)
End Try



thanks

Mod Edit: Please use code tags when posting your code. Code tags are used like so => code.gif

Thanks,
PsychoCoder smile.gif
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Login Form With Text Box In Vb.net
15 Sep, 2008 - 05:29 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:

  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do

User is offlineProfile CardPM
+Quote Post

magicmonkey
RE: Login Form With Text Box In Vb.net
15 Sep, 2008 - 06:38 AM
Post #3

D.I.C Regular
***

Joined: 12 Sep, 2008
Posts: 484



Thanked: 84 times
My Contributions
QUOTE(nirmala82 @ 14 Sep, 2008 - 06:54 PM) *

hi frends,its bit urgent for me,can anyone find me coding of the below mentioned requirement,thank frens in advance those who r helping me...


need to give one number in textbox click login button,the text box value shld be chekd with the database table(borrower),if borrowernumber(one of the field in borrowertable) has the same value,if so, automatically go to next for which shld display all the information of thhe borrwers in datagrid with a label text visible at runtime...thanks
in form1:



I can't believe I am replying to this, but I think I translated what you are asking... What you should do is add a public sub to your Testforissues form, and call this sub to populate the form before you show it. This allows you to easily pass the cardnumber parameter. That is a much cleaner practice then cross referencing instances of forms. Next I think you may have to change a couple lines were you assign your datasource, I don't think you are using DefaultViewManager as it is intended.

CODE

Dim issues As New Testforissues  
issues.PopulateBorrower(txtcardnumber.Text.ToString)
issues.Show()


In your Testforissues form...
CODE

Public Sub PopulateBorrower(CardNumber as String)

    'Place your code currently in your form_load event here and use the CardNumber parameter above to build your SQL.
    cmd.CommandText = "select * from borrowers where cardnumber='" & CardNumber & "'"

    'And change your datasource to this
    da.Fill(ds, "borrowers")  
    DataGrid1.DataSource = ds
    DataGrid1.DataMember = "borrowers"

End Sub


Also all those MsgBox popups are bad, only use them when an error occurs. For status/informational messages use a label control or a status bar to display the other messages. If you are doing it for debug purposes use Debug.WriteLine("Status message") and you can view the messages in you Output window within VS.

Also you should never get into the habit of building SQL statements like you are. They are open to injection. Look into paramertized queries or stored procedures if possible.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 03:46PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month