?
Solved

DataAdpater

Posted on 2006-07-21
2
Medium Priority
?
194 Views
Last Modified: 2010-04-17
In attempt to get away from using the DataAdapter Wizard - it's causing problems with the connection the we are using.  I need to hand code in the adpaters.  I'm looking for a good example of one that is using a stored procedure that needs a parameter or multiple parameters.

Any help would be appreciated.

my connectionstring is using the app.config file (example)

'SqlConnection1
        '
        Me.SqlConnection1.ConnectionString = AppSettings.Get("ABRConn")


When using the wizard this string can not be selected and if the connection string in the adpater is changed with the wizard it removes the above code.


thanks in advance.


0
Comment
Question by:TimSweet220
2 Comments
 
LVL 14

Accepted Solution

by:
shahprabal earned 1600 total points
ID: 17157834
Dim myConn As OleDbConnection = New OleDbConnection _
   ( "Provider=SQLOLEDB; Data Source=localhost; " & _
   "Integrated Security=SSPI; Initial Catalog=northwind" )
Dim salesCmd As OleDbCommand = New OleDbCommand _
   ( "SalesByCategory", myConn )
salesCmd.CommandType = CommandType.StoredProcedure

Dim myParam As OleDbParameter = salesCmd.Parameters.Add _
   ( "@CategoryName", OleDbType.NVarChar, 15 )
myParam.Value = "Beverages"

myConn.Open ( )
Dim myReader As OleDbDataReader = salesCmd.ExecuteReader ( )
Response.Write ( myReader.GetName ( 0 ) & ", " & _
   myReader.GetName ( 1 ) & "<br>" )

Do While myReader.Read ( )
   Response.Write ( myReader.GetString ( 0 ) & ", " & _
      myReader.GetDecimal ( 1 ) & "<br>" )
Loop

myReader.Close ( )
myConn.Close ( )
0
 
LVL 2

Assisted Solution

by:JohnWoo
JohnWoo earned 400 total points
ID: 17159902
You may want to put your connection string into an external text file instead of into the config file. Then u retrieve it everytime when your system runs by reading that file.

next you can write out your stored procedure in SQL server. You can refer to the following link on how to pass parameter into the stored procedure you have written:

http://www.codeproject.com/dotnet/NET_Data_Access.asp
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Progress
Introduction to Processes

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question