473,396 Members | 1,886 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.

VS 2005 ADO.Net Basics

Hi everyone,

I'm a VB6 developer who has recently installed Visual Studio 2005 and I want
to get my hands dirty with VB.NET 2005! I'm struggling with database
connections, and I mean floundering!

Most of the examples I've found have been using forms and controls but I
would like to do it all in code. You could set up a connection and recordset
very easily in classic ADO so I don't suppose it's that hard but I'm stuck.
All I want to do is create a connection to a SQL database, query a table (any
table) and then set the value of a string variable with the value of a field
in my returned records.

Can anyone give me a basic example to set me on my way?

I would really appreciate it.

Thanks in advance for any help
Paul
Oct 31 '07 #1
7 3079
Doing a quick search on google, using the keywords: vb ado.net howto, I
came across:
http://samples.gotdotnet.com/quickst...soverview.aspx
among others.

HTH
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:1A**********************************@microsof t.com...
Hi everyone,

I'm a VB6 developer who has recently installed Visual Studio 2005 and I
want
to get my hands dirty with VB.NET 2005! I'm struggling with database
connections, and I mean floundering!

Most of the examples I've found have been using forms and controls but I
would like to do it all in code. You could set up a connection and
recordset
very easily in classic ADO so I don't suppose it's that hard but I'm
stuck.
All I want to do is create a connection to a SQL database, query a table
(any
table) and then set the value of a string variable with the value of a
field
in my returned records.

Can anyone give me a basic example to set me on my way?

I would really appreciate it.

Thanks in advance for any help
Paul

Oct 31 '07 #2
try this .... http://www.connectionstrings.com/

--
Terry
"Paul" wrote:
Hi everyone,

I'm a VB6 developer who has recently installed Visual Studio 2005 and I want
to get my hands dirty with VB.NET 2005! I'm struggling with database
connections, and I mean floundering!

Most of the examples I've found have been using forms and controls but I
would like to do it all in code. You could set up a connection and recordset
very easily in classic ADO so I don't suppose it's that hard but I'm stuck.
All I want to do is create a connection to a SQL database, query a table (any
table) and then set the value of a string variable with the value of a field
in my returned records.

Can anyone give me a basic example to set me on my way?

I would really appreciate it.

Thanks in advance for any help
Paul
Oct 31 '07 #3
On Oct 31, 11:57 am, Paul <P...@discussions.microsoft.comwrote:
Hi everyone,

I'm a VB6 developer who has recently installed Visual Studio 2005 and I want
to get my hands dirty with VB.NET 2005! I'm struggling with database
connections, and I mean floundering!

Most of the examples I've found have been using forms and controls but I
would like to do it all in code. You could set up a connection and recordset
very easily in classic ADO so I don't suppose it's that hard but I'm stuck.
All I want to do is create a connection to a SQL database, query a table (any
table) and then set the value of a string variable with the value of a field
in my returned records.

Can anyone give me a basic example to set me on my way?

I would really appreciate it.

Thanks in advance for any help
Paul
System.Data.SQLClient.SQLConnection = ADODB.Connection
System.Data.SQLClient.SQLCommand = ADODB.Command
System.Data.SqlClient.SqlDataReader = ADODB.Recordset (almost)

The datareader doesn't contain the AddNew() or Update() these things
need to be done manually or look into using SqlDataAdapters (I'm not
too familiar with them but I know you can shortcut a lot of work with
them).
Oct 31 '07 #4

If you like "code based", then check out a few of these samples:

http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!140.entry

http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!139.entry

The 1.1 is a letter better put together, but the 2.0 version works good as
well.

I would look up the EnterpriseLibrary.Data (and if you get my samples above,
you should replace SqlHelper calls with EnterpriseLibrary.Data calls )

This is a pretty good sample
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!158.entry
of using the EnterpriseLibrary, you just need to whack out the WCF stuff
probably.

When you use the EnterpriseLibrary, you start seeing VERY clean code like
this:

private readonly string PROC_ZEBRA_GET_ALL =
"[dbo].[uspZebraGetAll]";
public IDataReader ZebraGetAll()
{
IDataReader idr = null;
try
{
Database db = base.GetDatabase();//base code is in the
download
DbCommand dbc =
db.GetStoredProcCommand(this.PROC_ZEBRA_GET_ALL);
idr = db.ExecuteReader (dbc);
return idr;
}
finally
{
}
}
All url's above have downloadable code.....you just gotta find the link.
Rule #1
ADO.Net is not ADO.
#2 Do not create ADODB objects in dotnet code. (If you use an upgrade
wizard, you might get this).

Google
IDataReader LoadDataSet
and you'll find alot of info.
The code is in C#, but easily translatable. Also, if you translate, you'll
really see whats going on as your replicate the project into another dotNet
language.


"Paul" <Pa**@discussions.microsoft.comwrote in message
news:1A**********************************@microsof t.com...
Hi everyone,

I'm a VB6 developer who has recently installed Visual Studio 2005 and I
want
to get my hands dirty with VB.NET 2005! I'm struggling with database
connections, and I mean floundering!

Most of the examples I've found have been using forms and controls but I
would like to do it all in code. You could set up a connection and
recordset
very easily in classic ADO so I don't suppose it's that hard but I'm
stuck.
All I want to do is create a connection to a SQL database, query a table
(any
table) and then set the value of a string variable with the value of a
field
in my returned records.

Can anyone give me a basic example to set me on my way?

I would really appreciate it.

Thanks in advance for any help
Paul

Oct 31 '07 #5
Paul,

In most of our tips we are only using code, it needs to much words to do it
using the designer.

http://www.vb-tips.com/dbpages.aspx?IA=AD1

Cor

Nov 1 '07 #6
Paul,
Try something like

Public Shared Function GetDataTable(ByVal conn As SqlConnection, ByVal
tablename As String) As DataTable

Dim _dt As New DataTable
Try
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Dim _cmd As New SqlCommand
_cmd.Connection = conn
_cmd.CommandType = CommandType.Text
_cmd.CommandText = "select * from " & tablename
Dim da As New SqlDataAdapter(_cmd)
da.Fill(_dt)
Finally
conn.Close()
End Try
Return _dt
End Function

this will give you a DataTable full of data, you can then iterate through
its Rows collection to inspect the data (use its item(ColumnNumber) or
ItemArray properties)When you are happy with this have alook at
theSQLDataReader, the ADO.NET equivalent of a 'firehose'

Guy

Guy
"Paul" wrote:
Hi everyone,

I'm a VB6 developer who has recently installed Visual Studio 2005 and I want
to get my hands dirty with VB.NET 2005! I'm struggling with database
connections, and I mean floundering!

Most of the examples I've found have been using forms and controls but I
would like to do it all in code. You could set up a connection and recordset
very easily in classic ADO so I don't suppose it's that hard but I'm stuck.
All I want to do is create a connection to a SQL database, query a table (any
table) and then set the value of a string variable with the value of a field
in my returned records.

Can anyone give me a basic example to set me on my way?

I would really appreciate it.

Thanks in advance for any help
Paul
Nov 1 '07 #7
Dear All,

Thank you very much for all your help. That's exactly the kind of help I was
after.

Many thanks
Paul

"guy" wrote:
Paul,
Try something like

Public Shared Function GetDataTable(ByVal conn As SqlConnection, ByVal
tablename As String) As DataTable

Dim _dt As New DataTable
Try
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Dim _cmd As New SqlCommand
_cmd.Connection = conn
_cmd.CommandType = CommandType.Text
_cmd.CommandText = "select * from " & tablename
Dim da As New SqlDataAdapter(_cmd)
da.Fill(_dt)
Finally
conn.Close()
End Try
Return _dt
End Function

this will give you a DataTable full of data, you can then iterate through
its Rows collection to inspect the data (use its item(ColumnNumber) or
ItemArray properties)When you are happy with this have alook at
theSQLDataReader, the ADO.NET equivalent of a 'firehose'

Guy

Guy
"Paul" wrote:
Hi everyone,

I'm a VB6 developer who has recently installed Visual Studio 2005 and I want
to get my hands dirty with VB.NET 2005! I'm struggling with database
connections, and I mean floundering!

Most of the examples I've found have been using forms and controls but I
would like to do it all in code. You could set up a connection and recordset
very easily in classic ADO so I don't suppose it's that hard but I'm stuck.
All I want to do is create a connection to a SQL database, query a table (any
table) and then set the value of a string variable with the value of a field
in my returned records.

Can anyone give me a basic example to set me on my way?

I would really appreciate it.

Thanks in advance for any help
Paul
Nov 6 '07 #8

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

Similar topics

3
by: Dr. International | last post by:
Did You Know: a.. By 2010, emerging PC markets like China, Russia and India will add 566 million new PCs. (Source: Forrester Research) b.. Web users are up to four times more likely to...
0
by: Lester Knutsen | last post by:
Washington Area IBM Informix/DB2 User Group meeting - June 7, 2005 -------------------------------------------------------------- Mark the date, our next user group meeting will be another...
6
by: sathyashrayan | last post by:
Following are the selected thread from the date:30-jan-2005 to 31-jan-2005. I did not use any name because of the subject is important. You can get the original thread by typing the subject...
6
by: Russ | last post by:
This really is the worst Microsoft product I have ever had the misfortune to work with. After the excellent feattures and stability of VS.NET 2002 and 2003, I was confident enough to start a...
1
by: Georg Gast | last post by:
Hi, i'm looking for a good book to learn .NET and VS2005 (C++) . I know MSVC6 (C++) very good. Is there a book like "The Bible" (The C++ Programming Language) from Bjarne Stroustrup for...
10
by: Steve | last post by:
I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains custom functions. I believe I need to use COM interop to allow VBA code in Excel 2002 to access it. I've studied...
20
by: weight gain 2000 | last post by:
Hello all! I'm looking for a very good book for an absolute beginner on VB.net or VB 2005 with emphasis on databases. What would you reccommend? Thanks!
16
by: Omar Abid | last post by:
Hi every body, Im using VB 2005 to create a program that open SQL Data base The problem that i want to detect the tables of a database so how can i know a data base tables instantly Thank you...
2
by: Matt | last post by:
I've coded using VBA on top of MS Excel for the last 2 years (40 hours a week). I've stepped up to VS C# 2005 Express / SQL Server 2005 Express a couple months ago, but the videos that I downloaded...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
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.