Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

         public DataView GetData()
         {
             dynamic SelectQry = "SELECT RTRIM(Username) as [User Name],RTRIM(Password) as [Password],RTRIM(Name) as [Name],RTRIM(ContactNo) as [Contact No.],RTRIM(Email) as [Email ID],RTRIM(joiningdate) as [Date Of Joining] FROM registration";
             DataSet SampleSource = new DataSet();
             DataView TableView = null;
             try
             {
                 SqlCommand SampleCommand = new SqlCommand();
                 dynamic SampleDataAdapter = new SqlDataAdapter();
                 SampleCommand.CommandText = SelectQry;
                 SampleCommand.Connection = Connection;
                 SampleDataAdapter.SelectCommand = SampleCommand;
                 SampleDataAdapter.Fill(SampleSource);
                 TableView = SampleSource.Tables[0].DefaultView;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             return TableView;
         }