Wednesday, May 1, 2013

sql command


public static void GetStudentById(int studentID)
        {
            using (OleDbConnection connection = new OleDbConnection
                 (@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Students.mdb;Persist Security Info=True"))
            {
                connection.Open();
                using (OleDbCommand command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "GetStudentById";

                    command.Parameters.AddWithValue("@studentID", studentID);

                    OleDbDataAdapter adapter = new OleDbDataAdapter(command);
                    adapter.TableMappings.Add("Table", "Students");

                    StudentsDataSet dataset = new StudentsDataSet();

                    adapter.Fill(dataset);

                    DataSetDump.ShowDSInOutputWindow(dataset);

                }
            }

No comments:

Post a Comment