Using If .. Else..End if  with ADO.net
Using If .. Else..End if  with ADO.net
Using If .. Else..End if  with ADO.net
Using If .. Else..End if  with ADO.net
Using If .. Else..End if  with ADO.net
Using If .. Else..End if  with ADO.net Using If .. Else..End if  with ADO.net Using If .. Else..End if  with ADO.net Using If .. Else..End if  with ADO.net Using If .. Else..End if  with ADO.net Using If .. Else..End if  with ADO.net Using If .. Else..End if  with ADO.net Using If .. Else..End if  with ADO.net
Using If .. Else..End if  with ADO.net Using If .. Else..End if  with ADO.net
Using If .. Else..End if  with ADO.net
Go Back  Xtreme Visual Basic Talk > > > Using If .. Else..End if with ADO.net


Reply
 
Thread Tools Display Modes
  #1  
Old 09-29-2008, 10:55 AM
nader75 nader75 is offline
Centurion
 
Join Date: Feb 2004
Posts: 181
Default Using If .. Else..End if with ADO.net


I tried this code to check if the data in textbox1 not eaqual to any data in column name, so insert the data that in the textboxes to the table1. Esle.. do another thing.
But it didn't success with me.

Code:
Dim conn As New OleDbConnection()
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source =" & Application.StartupPath & "\DataBaseName.mdb "

Dim cmd As New OleDbCommand
cmd.Connection = conn
IF cmd.CommandText = "INSERT INTO Table1(Name,Place,Mobile) _
  " & "values ('" & TextBox1.Text & "','" & TextBox2.Text & _ 
 "','" & TextBox3.Text & "') where name <> '" & TextBox1.Text & "'" Then 
cmd.CommandType = CommandType.Text 
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
exit sub 
Else  
Do another thing
End if
Reply With Quote
  #2  
Old 09-30-2008, 07:33 AM
wayneph's Avatar
waynephUsing If .. Else..End if  with ADO.net wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

There are a few things wrong with your code...
1. For Starters, in the middle of your IF statment's conditional clause, you are just setting the SQL for your command. You don't really "check" anything.
2. In your SQL Statement, you can't have a WHERE clause on an INSERT statement. (Unless you're using a SELECT to determine what's being inserted.)

Since you're using Access, I think the easiest thing would be to use multiple queries. First use a single SELECT statement to see if the value entered in the application already exists in the database. (I'd use ExecuteScalar, and just return a True/False or something like that.) After you run that query, then check the results in an IF statment. If it passes your test, set up your INSERT statement (without the where clause since you've already checked to see if it exists) and save the data. If it doesn't pass the test, do what ever else you wanted to do.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #3  
Old 09-30-2008, 08:55 AM
nader75 nader75 is offline
Centurion
 
Join Date: Feb 2004
Posts: 181
Default

Thank you for help!.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Using If .. Else..End if  with ADO.net
Using If .. Else..End if  with ADO.net
Using If .. Else..End if  with ADO.net Using If .. Else..End if  with ADO.net
Using If .. Else..End if  with ADO.net
Using If .. Else..End if  with ADO.net
Using If .. Else..End if  with ADO.net Using If .. Else..End if  with ADO.net Using If .. Else..End if  with ADO.net Using If .. Else..End if  with ADO.net Using If .. Else..End if  with ADO.net Using If .. Else..End if  with ADO.net Using If .. Else..End if  with ADO.net
Using If .. Else..End if  with ADO.net
Using If .. Else..End if  with ADO.net
 
Using If .. Else..End if  with ADO.net
Using If .. Else..End if  with ADO.net
 
-->