2 Replies - 9276 Views - Last Post: 15 September 2008 - 07:38 AM Rate Topic: -----

#1 nirmala82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 12-September 08

login form with text box in vb.net

Post icon  Posted 14 September 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:

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:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: login form with text box in vb.net

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: login form with text box in vb.net

Posted 15 September 2008 - 06:29 AM

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

Was This Post Helpful? 0
  • +
  • -

#3 magicmonkey  Icon User is offline

  • D.I.C Regular

Reputation: 106
  • View blog
  • Posts: 484
  • Joined: 12-September 08

Re: login form with text box in vb.net

Posted 15 September 2008 - 07:38 AM

View Postnirmala82, on 14 Sep, 2008 - 06:54 PM, said:

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.

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



In your Testforissues form...
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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1