Microsoft has built "blocks" for you to reuse as part of an application.
One of those is called the "Data Access Application Block" that hides some of this complexity.
See it at
http://msdn2.microsoft.com/en-us/library/aa480458.aspx>I have been playing around with getting data from SQL, and thinking about how I would go about designing a Data Layer Object. I have always worked with stored procedures, so I am very comfortable with setting up parameters. I do need to ask though .. the following code seems to be a lot of work to pull a single value from SQL? Is this code correct or have I over complicated things?
>
>
>DataSet ds;
>DataTable dt;
>DataRow dr;
>SqlDataAdapter oDataAdapter;
>int lnRecords;
>
>ds = new DataSet();
>this.map_ConnectToData();
>
>oDataAdapter = new SqlDataAdapter();
>oDataAdapter.SelectCommand = new SqlCommand("map_rlb_Logins_validate", this.oConnection);
>oDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure ;
>
>oDataAdapter.SelectCommand.Parameters.Add("@tcUserID",SqlDbType.Char, 20).Value = tcLoginID;
>oDataAdapter.SelectCommand.Parameters.Add("@tcPassword",SqlDbType.Char, 20).Value = tcPassword;
>lnRecords = oDataAdapter.Fill(ds, "cData");
>
>MessageBox.Show(lnRecords.ToString());
>
>dt = ds.Tables["cData"];
>dr = ds.Tables[0].Rows[0];
>
>MessageBox.Show(dr["cuserid"].ToString());
>
>
>
>TIA, -Mark
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com