473,396 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

VB.NET using inline sql

I have the following questions about VB.NET interfacing with sql server 2000:
1. I have heard that VB.NET can run with inline SQL. Can you show me how to
use
inline sql to access a sql server 2000 database?
2. How do you setup stored procedures using Visual basic.net?
3. What is better to use and why, either inline sql or stored procedures?
4. Can you execute a visual basic.net program from a DTS package? If so,
show would you accomplish this task?
Nov 21 '05 #1
4 4972
"Wendy Elizabeth" <We************@discussions.microsoft.com> schrieb:
I have the following questions about VB.NET interfacing with sql server
2000:
1. I have heard that VB.NET can run with inline SQL. Can you show me how
to
use
inline sql to access a sql server 2000 database?


If you are referring to the ability of mixing SQL with VB.NET code, this
cannot be done in current versions of the VB.NET programming language, and
will not be supported in the upcoming release of Visual Studio 2005.

The release of VS following on Whidbey (VS 2005) has the codename Orcas and
will include what's currently called LINQ (Language Integrated Query). It's
planned to support LINQ in both VB and C#. LINQ will allow to formulate SQL
queries directly inside the source code, regardless of the data the query is
working on. This means that you can query instances of .NET classes or
different DBMS which provide support for such queries.

The LINQ Project
<URL:http://msdn.microsoft.com/netframework/future/linq/>

Overview of Visual Basic 9.0
<URL:http://msdn.microsoft.com/library/en-us/dnvs05/html/vb9overview.asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
Wendy,

Just open a form. Go to the toolbox and drag a sqldatadapter wizard on your
form and follow the steps, than you all kind of SQL code that is created if
yu open your designer part of a form.

With that wizard you can as well make stored procedures. I prefer at the
start to use dynamic SQL (sqlStrings). It is almost no problem to change
that when you are ready to a SP.

(It is easy to build everything by hand as well if you are more used to it).

For pure datatransaction SQL it is better to use stored procedures. However
if you have to make them complex to use them in a general way and they are
not often used, than dynamic SQL seems to be better, because the SP has to
be compiled every time at first use.

If are ready with the wizard and than rightclick on the icon
(sqldataadapter), than you can select to generate Dataset to create a
strongly typed dataset from that.

If you want to use an SQL string inside the code (by instance to create a
new datatable) than you can process it with the
system.data.sqlclient.sqlcommand class methods as
executequery (this gives nothing back) (except the rows affected)
executescalar(this gives back the first value)

or read a resultset with
system.data.sqlclient.sqldatareader

From a DTS package you can make a VB6 program, that you have to convert to
VBNet if you want to use that.

There is inbuild in the current and next VBNet version 'Expression syntax'
to process dataset/datatables. (This is not SQL, what a lot of people at the
start think and than have problems).

The build in expression language (or better a new one) is planned to be
extended for more general use in future, be aware it is not SQL syntax.
(However, it will as every expression syntax look like that. SQL was not
the first expression language).

I hope this helps,

Cor

"Wendy Elizabeth" <We************@discussions.microsoft.com> schreef in
bericht news:F5**********************************@microsof t.com...
I have the following questions about VB.NET interfacing with sql server
2000:
1. I have heard that VB.NET can run with inline SQL. Can you show me how
to
use
inline sql to access a sql server 2000 database?
2. How do you setup stored procedures using Visual basic.net?
3. What is better to use and why, either inline sql or stored procedures?
4. Can you execute a visual basic.net program from a DTS package? If so,
show would you accomplish this task?

Nov 21 '05 #3
Cor Ligthert:

Thank you very much for your assistance! How do you setup dynamic SQL?

"Cor Ligthert [MVP]" wrote:
Wendy,

Just open a form. Go to the toolbox and drag a sqldatadapter wizard on your
form and follow the steps, than you all kind of SQL code that is created if
yu open your designer part of a form.

With that wizard you can as well make stored procedures. I prefer at the
start to use dynamic SQL (sqlStrings). It is almost no problem to change
that when you are ready to a SP.

(It is easy to build everything by hand as well if you are more used to it).

For pure datatransaction SQL it is better to use stored procedures. However
if you have to make them complex to use them in a general way and they are
not often used, than dynamic SQL seems to be better, because the SP has to
be compiled every time at first use.

If are ready with the wizard and than rightclick on the icon
(sqldataadapter), than you can select to generate Dataset to create a
strongly typed dataset from that.

If you want to use an SQL string inside the code (by instance to create a
new datatable) than you can process it with the
system.data.sqlclient.sqlcommand class methods as
executequery (this gives nothing back) (except the rows affected)
executescalar(this gives back the first value)

or read a resultset with
system.data.sqlclient.sqldatareader

From a DTS package you can make a VB6 program, that you have to convert to
VBNet if you want to use that.

There is inbuild in the current and next VBNet version 'Expression syntax'
to process dataset/datatables. (This is not SQL, what a lot of people at the
start think and than have problems).

The build in expression language (or better a new one) is planned to be
extended for more general use in future, be aware it is not SQL syntax.
(However, it will as every expression syntax look like that. SQL was not
the first expression language).

I hope this helps,

Cor

"Wendy Elizabeth" <We************@discussions.microsoft.com> schreef in
bericht news:F5**********************************@microsof t.com...
I have the following questions about VB.NET interfacing with sql server
2000:
1. I have heard that VB.NET can run with inline SQL. Can you show me how
to
use
inline sql to access a sql server 2000 database?
2. How do you setup stored procedures using Visual basic.net?
3. What is better to use and why, either inline sql or stored procedures?
4. Can you execute a visual basic.net program from a DTS package? If so,
show would you accomplish this task?


Nov 21 '05 #4

Wendy - if your definition of "inline SQL" is to execute a string like

Dim strSelect as string = "Select * from tbl" <-- can build the string
with whatever SQL Query you would like...I would not recommend
this...even though it is pretty flexible, but has alot of security
holes and you need to be "anal" when you code this way...

but if you need an example...here is some psuedo code:
Dim strInfo as string
dim conn as SqlConnection = New SqlConnection(<connection string>)
dim cmd as SqlCommand
strInfo = "<build query>"
conn.open()
cmd = New SqlCommand(strInfo, conn)
<execute>
...

Personally, I always use Stored Procedure, it is more secure and easier
to support (IMHO)...Here is some psuedo code:

dim conn as SqlConnection = New SqlConnection(<connection string>)
Dim cmd As SqlCommand = New SqlCommand(<store proc name>, conn)
cmd.CommandType = CommandType.StoredProcedure
Dim prm1 As SqlParameter = cmd.Parameters.Add("@storeprocvariablename",
SqlDbType.VarChar, 15)
prm1.Value = "<parameter value that you want to pass>"
conn.Open()
Dim myReader As SqlDataReader = cmd.ExecuteReader()
<loop through myReader for values>
As for Dymamic Sql, it is basically a stored procedure where you build
a string/varchar variable and execute the string...I tend to stay away
from this for this reason....Dynamic SQL (correct me if I am wrong)
will always take the same amount of time to execute because the query
is not machine compiled (or whatever SQL does to optimize queries).
Versus, Store procs...Stored procs get optimized (in most cases) and
you will notice that a query will take less longer to execute on
subsequent calls to the store procs...

anyway, hope this helps.

Ralph
--
rviray
------------------------------------------------------------------------
rviray's Profile: http://www.msusenet.com/member.php?userid=4211
View this thread: http://www.msusenet.com/t-1871082249

Nov 21 '05 #5

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

Similar topics

2
by: Jon Maz | last post by:
Hi, Simple one. The C# code behind for a .aspx page can have a 'namespace alias', as here: using AdsBusiness = Wrox.WebModules.AdsManager.Business; Question: can you do this with inline...
5
by: Tony Johansson | last post by:
Hello experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that sound strange. Here is the whole section: It says" Because...
18
by: Method Man | last post by:
If I don't care about the size of my executable or compile time, is there any reason why I wouldn't want to inline every function in my code to make the program run more efficient?
0
by: dotnet | last post by:
I am trying to make a page that is changing the page schema(colors and graphics) depends on the specific value (for example, test.aspx?page=1) I have so far achieved accepting page values (with...
3
by: Jack Frost | last post by:
What is the consensus on putting ASP.NET code inline in the html doc versus using code behind and C#. I find it confusing when pages include code in both places. For example, using...
2
by: Showjumper | last post by:
Is there a peformance hit when using inline code? As an example, lets i store a user's preferences for backgtound color of a page. When he/she logs in, i stick the color value into their session...
1
by: itaitai2003 | last post by:
I'm attempting to configure the DISPLAY attribute using inline code but without success. (I don't want to use the Panel) Any ideas? <div id="panel" style="DISPLAY: <%# GetDisplayStatus() %> ">...
6
by: Anders M | last post by:
I'm trying to use Inline-code to call Page_load, Page_Init or Page_PreRender methods. I've also got a code behind c#-file. I can define inline methods for buttons and so on...that works fine....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.