Connection to SQL

  • Thread starter Thread starter David Lozzi
  • Start date Start date
D

David Lozzi

What is the best way to connect to a SQL database from ASP.NET?

Thanks,
 
System.Data.SqlClient NameSpace.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
//This code inserts, updates or deletes a record(s) in a table using a
stored procedure with a single parameter.
//It would need to be modified for a Select statement that retrieved
records.

SqlConnection sqlConn = new SqlConnection("your connection string goes
here");
sqlConn.Open();
SqlCommand sqlComm = new SqlCommand("Your_stored_procedure_name", sqlConn);
SqlParameter prm1 = new SqlParameter("@my_prm",varchar,10);
prm1.value = "neat";
sqlComm.Parameters.Add(prm1);
sqlComm.CommandType = CommandType.StoredProcedure;
Int32 intNumberOfRecordsAffected = sqlComm.ExecuteNonQuery();
sqlConn.Close();

Hope this helps.

Mark
www.dovetaildatabases.com
 
Could I have a little more information? Like an example or a MS reference?
 
If i put System.Data.SqlClient. infront of it, it works fine. How can I
'declare' this for the entire doc?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top