Google Brother Up

Showing posts with label Connection. Show all posts
Showing posts with label Connection. Show all posts

2008/08/14

ConnectionString in Web.Config

(configuration)
(appSettings)
(add key="mstrConnectionString" value="user id=abcd; password=1234; server=VAIJAYANTA-PC\SQLEXPRESS; database="VaijayantaTest" /)
(/appSettings)
(/configuration)

or

(configuration)
(connectionStrings)
(add name="mstrConnectionString" connectionString="user id=abcd; password=1234 server=VAIJAYANTA-PC\SQLEXPRESS; database="VaijayantaTest" /)
(/connectionStrings)
(/configuration)

string StrCon;

StrCon = ConfigurationSettings.AppSettings.Get("mstrConnectionString");

Sqlconnection conn = new SqlConnection(StrCon );
conn.Open();
SqlCommand cmd = new SqlCommand(select,conn);

rest follows.........

72 unique visitors

2008/08/05

How to write a Database Connection in Dot Net

---------------------------------------------------------------------------

source = "server=(local); integrated security=SSPI; database=Northwind";

select = "select * from Customers";
Sqlconnection conn = new SqlConnection(source);

conn.Open();

SqlCommand cmd = new SqlCommand(select,conn);

int rowsReturned = cmd.ExecuteNonQuery(); //returns no of rows affected

---------------------------
SqlDataReader reader = cmd.ExecuteReader();

while(reader.Read())

{

ConsoleWriteline(reader[0], reader[1]); //returns a set of values

} // by iterating through records

-------------------------


object o = cmd.ExecuteScalar();

Console.WriteLine(o); // returns a column

-----------------

XmlReader xr = cmd.ExecuteXmlReader();

xr.Read(); // returns a XmlReaderObject

--------------

SqlDataAdapter da = new SqlDataAdapter(select, conn);

DataSet ds = new DataSet();

da.Fill(ds,"Customers"); //runtime schema generation
---------------------------------------------------------------------------

68 unique visitors

2008/07/31

SQL Server Database ConnectionString

string strCon;
SqlConnection objCon = new SqlConnection();
string mstrConnectionstring = String.Empty;
public DataObject()
{
objCon = new SqlConnection();
strCon = ConfigurationSettings.AppSettings.Get("mstrConnectionstring");
objCon = new SqlConnection(strCon);
objCon.Open();
----------------------------------------
Inside WebConfig. Replace the ( and ) by <>.

(appSettings)(add key="mstrConnectionstring" value="user id= ab;password=**********; server=VAIJAYANTA-PC\SQLEXPRESS; database = Vaijayanta-Test")(/add)(/appSettings)

65 unique visitors

Drop Down List

1. http://www.janetsystems.co.uk/Articles/NetArticles/tabid/74/itemid/161/modid/449/Default.aspx