here...anway this is how i do it...
try it anyway ^^
dim k as integer
Public Sub Search()
k = 0 ' <==my flag if theres found data
con.open
dim dt as new DataTable("TableName")
dim rs as new oledb.oledbDataAdapter("Select * from TableName where Columnname='"& searchname &"' ",con)
rs.fill(dt)
'if your using datagridview..me? i use datagridview all the time i..just hide it ^^..
datagridview1.datasource = dt
datagridview1.refresh()
label1.text = dt****ws.count '<====this will be the flag ,,it counts the row numbers in the table dt("TableName")..
rs.dispose()
con.close
if val(label1.text) >= 1 then <<====when this value goes more than 1 or 1 then what you search is there..if not then value of label1 = 0 ..no data found
Msgbox("Data Found!")
k = 1
else
Msgbox("No Data Found!")
End if
End Sub
Public Sub Add_Data
con.open
dim rs as new oledb.oledbCommand("Insert into Tablename(colname1,colname2,colname3) values ( '"& colnameval1 &"' , '"& colnameval2 &"', '"& colnameval3 &"')",con) ' command for adding data into table..anyway..should have not included this.
rs.executenonquery
con.close
End sub
private sub button1_click
if k = 1 then '<<===remember the flag k as integer? ,,,,yep here it is
msgbox("Data already exist")
Else
msgbox("Can call add data")
add_data
End if
end sub