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..

First of all you have to construct the SELECT statement.

Dim sqlr="select column_name1 from table_name where column_name2=@col_value"

Prepare the command object.

Dim Cmd as New OleDbCommand
Cmd.CommandText=sql
Cmd.Connection=Cn 'Assign ref of connection object
Cmd.Parameters.AddWithValue("@col_value",textBox1.Text)

Execute the command using ExecuteScalar method.

Cn.Open()
 Dim result=Cmd.ExecuteScalar()
 Cn.Close()
 
 If IsNothing(Result) Then
     'Not found
 else
     TextBox2.Text=Result.ToString()
 End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.