Solved

DataAdpater

Posted on 2006-07-21
2
188 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 400 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 100 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
This is about my first experience with programming Arduino.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

803 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