Hello..
I am new to vb.net. Need to know how can I retrieve the value from compname field of my table, to the textbox7 in form i made.
While the user enters data in the textbox, i need to compare the entered textbox value, if it exists or not, in the database. If exists, It should enter the value in textbox. If not, it should pop up a message box asking user to add new contact.
I have inserted data using Oledbd command string.
Database : MS Access 2007
Kindly help me out. Your guidance would be highly appreciated.
Thank You..
Value from Database to textbox
Page 1 of 14 Replies - 2952 Views - Last Post: 26 September 2011 - 02:59 AM
Replies To: Value from Database to textbox
#2
Re: Value from Database to textbox
Posted 26 September 2011 - 01:28 AM
Hi,
Private Sub textbox7_leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textbox1.leave
Try
cn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
cn.Open()
cmd = New OleDbCommand("SELECT compname FROM table_name WHERE compname = '"& textbox7.text &"'", cn)
OleDbDataReader oReader=cmd.ExecuteReader();
IF(oReader.HasRow())THEN
While oReader.Read
textbox7.text= oReader["compname"].ToString()
End While
ELSE
MsgBox("add new contact.")
Catch myException As Exception
MsgBox("No Record Inserted" + myException.ToString())
Finally
cn.Close()
End Try
End Sub
#3
Re: Value from Database to textbox
Posted 26 September 2011 - 01:48 AM
Vishu Sukhdev, on 26 September 2011 - 01:28 AM, said:
Hi,
Private Sub textbox7_leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textbox1.leave
Try
cn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
cn.Open()
cmd = New OleDbCommand("SELECT compname FROM table_name WHERE compname = '"& textbox7.text &"'", cn)
OleDbDataReader oReader=cmd.ExecuteReader();
IF(oReader.HasRow())THEN
While oReader.Read
textbox7.text= oReader["compname"].ToString()
End While
ELSE
MsgBox("add new contact.")
Catch myException As Exception
MsgBox("No Record Inserted" + myException.ToString())
Finally
cn.Close()
End Try
End Sub
Hello.. Thanks for reply..
but this line :
textbox7.text= oReader["compname"].ToString()
is giving an error saying "value of the type system.data.oledb.oledbdatareader cannot be converted to string type"..
Thank you again !!
#4
Re: Value from Database to textbox
Posted 26 September 2011 - 02:50 AM
IF oReader.HasRow THEN
Do While oReader.Read
textbox7.text = oReader(0)
Loop
ELSE
MsgBox("add new contact.")
END IF
Do While oReader.Read
textbox7.text = oReader(0)
Loop
ELSE
MsgBox("add new contact.")
END IF
#5
Re: Value from Database to textbox
Posted 26 September 2011 - 02:59 AM
It worked.. Thank you so very much, again !!
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|