473,499 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add SQL statements in VB .NET

Hi,

I have just learned from the link
http://support.microsoft.com/kb/821765/EN-US/ to use the
database with VB .NET

From the example of the above link, if I want to use the
table Student as reference table, I need to verify if the
SNo existing in the database, then the SName is matching
with that SNo is existed in the database. The Error to
handle the case will be:

IDERROR=1 IF SNo does not have that ID
IDERROR=2 IF SName does not match with the existing ID.

The Wizard from the "OleDbDataAdapter" automatically
generate the four SQL update, delete, insert... for me. I
want to add a SQL statements as the following:

SELECT *
FROM student
WHERE student.SNo="Input from the textbox of VB .NET".
If the return is null, the IDERROR=1

SELECT *
FROM student
WHERE student.SNo="Input from the textbox of VB .NET"
AND student.SName="Input from the textbox of VB .NET"
If the return is null, the IDERROR=2

Could someone help me to accomplish it, please.

Thanks,
/CC.

Nov 21 '05 #1
3 3227
Charlie,

I think that you can use for your question the SQLcommand.executescalar

http://msdn.microsoft.com/library/de...calartopic.asp

Go up in the links in the page how to use this.

I hope this helps?

Cor

"CharlieChau" <co**********@hotmail.com>
Hi,

I have just learned from the link
http://support.microsoft.com/kb/821765/EN-US/ to use the
database with VB .NET

From the example of the above link, if I want to use the
table Student as reference table, I need to verify if the
SNo existing in the database, then the SName is matching
with that SNo is existed in the database. The Error to
handle the case will be:

IDERROR=1 IF SNo does not have that ID
IDERROR=2 IF SName does not match with the existing ID.

The Wizard from the "OleDbDataAdapter" automatically
generate the four SQL update, delete, insert... for me. I
want to add a SQL statements as the following:

SELECT *
FROM student
WHERE student.SNo="Input from the textbox of VB .NET".
If the return is null, the IDERROR=1

SELECT *
FROM student
WHERE student.SNo="Input from the textbox of VB .NET"
AND student.SName="Input from the textbox of VB .NET"
If the return is null, the IDERROR=2

Could someone help me to accomplish it, please.

Thanks,
/CC.

Nov 21 '05 #2
thanks you very much Cor Lightert. I did try your
suggestion with the following code:

Dim SqlConnection1 As SqlConnection
SqlConnection1 = New SqlConnection("server =
localhost;uid=;password=;database=testdb")
Dim SQLStatement As String = "SELECT * FROM
student"
Dim RecordCount As Integer
Dim SelectCommand As New SqlClient.SqlCommand
(SQLStatement, SqlConnection1)
Try
SqlConnection1.Open()
RecordCount = CInt(SelectCommand.ExecuteScalar
())
Catch ex As Exception
MessageBox.Show("Failed to execute command")
Finally
SqlConnection1.Close()
End Try
MessageBox.Show("Customers table contains " &
RecordCount & " records")

But I can not well establish the connection. It seems to
me that the parameters SqlConnection1 does not work well,
but I do not know which parameters. Since I always get
the catch error message: ("Failed to execute command").
Could you give me some more hints.

Thanks,
/CC.
-----Original Message-----
Charlie,

I think that you can use for your question the SQLcommand.executescalar
http://msdn.microsoft.com/library/default.asp? url=/library/en-
us/cpref/html/frlrfsystemdatasqlclientsqlcommandclassexecu
tescalartopic.asp
Go up in the links in the page how to use this.

I hope this helps?

Cor

"CharlieChau" <co**********@hotmail.com>
Hi,

I have just learned from the link
http://support.microsoft.com/kb/821765/EN-US/ to use the database with VB .NET

From the example of the above link, if I want to use the table Student as reference table, I need to verify if the SNo existing in the database, then the SName is matching with that SNo is existed in the database. The Error to
handle the case will be:

IDERROR=1 IF SNo does not have that ID
IDERROR=2 IF SName does not match with the existing ID.

The Wizard from the "OleDbDataAdapter" automatically
generate the four SQL update, delete, insert... for me. I want to add a SQL statements as the following:

SELECT *
FROM student
WHERE student.SNo="Input from the textbox of VB .NET".
If the return is null, the IDERROR=1

SELECT *
FROM student
WHERE student.SNo="Input from the textbox of VB .NET"
AND student.SName="Input from the textbox of VB .NET"
If the return is null, the IDERROR=2

Could someone help me to accomplish it, please.

Thanks,
/CC.

.

Nov 21 '05 #3
Charlie,

Change the the lines without the > and see what it does (if there are no
security prolbems, I think it would work, however I can not see everything
in a message)
Dim SqlConnection1 As SqlConnection
SqlConnection1 = New SqlConnection("Server =
localhost;Database=YourDataBaseName;Integrated Security = SSPI")

'You had an OleDb connectionstring

Dim SQLStatement As String = "SELECT Count(*) FROM student" Dim RecordCount As Integer
Dim SelectCommand As New SqlClient.SqlCommand
(SQLStatement, SqlConnection1)
Try
SqlConnection1.Open()
RecordCount = CInt(SelectCommand.ExecuteScalar
())
Catch ex As Exception
MessageBox.Show(ex.tostring)

Finally
SqlConnection1.Close()
End Try
MessageBox.Show("Customers table contains " &
RecordCount & " records")


Maybe it will go better, (do not forget to put in the right name of your
database in the connectionstring).

I hope this helps?

Cor
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2486
by: Bart Nessux | last post by:
Should an if statement have a corresponding else statement? Or, is it OK to have an if statement by itself. For completeness, it seems the two should be together, but from experience I know that a...
9
2616
by: Jaime Wyant | last post by:
I know I've seen this somewhere, but can't seem to google it. Is there a way to use an alternate statement separator, other than the default ';'? jw
1
3790
by: Tom D | last post by:
I'm rewriting a database interface that our company currently has. Currently it's using the Pear::DB interface, but we found that that was introducing a bit too much overhead. I'm rewriting the...
39
6789
by: slogging_away | last post by:
Hi - I'm running Python 2.4.2 (#67, Sep 28 2005, 12:41:11) on win32, and have a script that makes numerous checks on text files, (configuration files), so discrepancies can be reported. The script...
0
1831
by: Fuzzyman | last post by:
Hello all, The following is a copy of a blog entry. It's asking a question about future statements and the built in compile function. I'd appreciate any pointers or comments about possible...
20
1988
by: Neroku | last post by:
Hello, i would like to know what the serious definition of statements and expressions is: i know an expression are evaluated to a value, i.e: 1 == 2 5+7 foo( 1,2) and a statement is...
2
2712
by: ojorus | last post by:
Hi! Some questions regarding the mysqli-extension (php5) 1) Prepared statements: If I understand things right, prepared statements will give better performance if you make several similar...
3
6584
by: Dmitri | last post by:
Hello! I have a developer that is playing around with some SQL statements using VB.NET. He has a test table in a SQL 2000 database, and he has about 2000 generated INSERT statements. When the...
0
1900
by: Gary Herron | last post by:
Ohad Frand wrote: There is no way you can consider 'elif', 'else', 'except', and 'from' statements. However, as someone pointed out, the kwlist from the keyword module is the closest thing we...
0
1432
by: Ohad Frand | last post by:
Hi Thanks a lot for your reply I think the main uses for it is to study the language and to see that I didn't miss anything else or that something is changed from one version to another. The...
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.