Archive
dreamweaver connection string
Hi, this article will show you have to create a base class in C # to retrieve data from your database SQL Server. First we must add the following using statement above the class declaration:
using System.Data.SqlClient;
The SqlClient namespace is the. NET Framework for SQL Server and contains a collection of classes used to perform various tasks in SQL Server. The three classes will be using from the SqlClient namespace, for our SunJavaUpdateSched are:
SqlCommand, SqlConnection, SqlDataReader;
Now we must declare our SqlCommand and SqlConnection classes: —
public class Data (
private SqlCommand oCommand;
oConnection private SqlConnection;)
Then, create a custom constructor that accepts a string parameter named connectionString and a string parameter called query. This builder then initialize our member variables private, SqlCommand SqlConnection:
public class Data (
private SqlCommand oCommand;
Private SqlConnection oConnection;
public data () (
oCommand = new SqlCommand ();
oConnection = new SqlConnection ();)
public data (connectionString, String query) (
oCommand = new SqlCommand ();
oConnection = new SqlConnection (connectionString);
= OCommand.Connection oConnection;
oCommand.CommandType = CommandType.Text;
= OCommand.CommandText consultation;)
RetrieveDataReader public SqlDataReader () (
oConnection.Dpen ();
SqlDataReader DR;
dr = oCommand.ExecuteReader (CommandBehavior.CloseConnection);
return dr;)
As can be seen when an instance of our connection to objects passing in the connection string to our database. Then set the connection property of the SqlCommand object to the SqlConnection object. Then set the CommandType property of our SqlCommand object to the CommandType Text. This indicates that you are sending to our commands in text form instead of using a stored procedure or table. Then set the CommandText property of the parameter query is passed in. Finally, develop a method to retrieve our data:
RetrieveDataReader public SqlDataReader () (
oConnection.Dpen ();
SqlDataReader dr;
dr = oCommand.ExecuteReader (CommandBehavior.CloseConnection);
return dr;)
Declare a public method that has a callback type RetrieveDataReader SqlDataReader. SqlDataReader class provides a way to read a forward-only stream of rows from a database SQL Server. Using the SqlConnection object calling the method Open (). We call the ExecuteReader method to return our SqlCommandObject our DataReader. We then return some data from SQL Server and join our repeater control to a Repeater control in our ASPX pages:
protected void Page_Load (object sender, EventArgs e) (
RepeaterControl.Data data = new RepeaterControl.Data (sp_GetUsers "," SELECT * FROM UserDetail ");
SqlDataReader dr = data.RetrieveDataReader ();
repUsers.DataSource = dr;
repUsers.DataBind ();
dr.Close ();)
Article by Tom Miller
Company: BluWeb
Home page: Website Design UK
BluWeb are a web company based in the UK offering quality website design, graphic design and SEO services.
Does your business need a website?
Does your existing website need a fresh new look and feel?
Do you want your website to rank well in the search engines?
Please visit out website at http://www.bluweb.co.uk
Dreamweaver MX 2004 ADO.NET Lesson 1 (part 2)