Solved

DataAdpater

Posted on 2006-07-21
2
187 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now