DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Conectarte A Una Base De Datos Con .net

04.06.2006
| 1267 views |
  • submit to reddit
        // description of your code here

SqlConnection conn = null;
SqlCommand cmd = null;
SqlDataReader dr = null;

String s = null;
Product prod = null;

try
{
	conn = new SqlConnection("Provider=SQLOLEDB;SERVER=sissql2;UID=sa;PWD=AlfaRoma440;DATABASE=genericatest2");

	s = " ";


	cmd = new SqlCommand(s,conn);
	dr = cmd.ExecuteReader();
	// lleno el objeto producto

	while( dr.Read())
	{

	}


}
catch (Exception ex)
{
	// poner el manejo de errores	
}
finally
{
	dr.Close();
	conn.Close();
}
dr.Close();
conn.Close();
return prod;
}