calling a field and format

May 14, 2009 at 7:22 PM

I am trying to call/isolate the field InspectionSummary.InspectionSummaryDate so I can do a Replace on it.  Basically replace all "-" with "/". 

I can't seem to be able to do a Replace from the SQL.  I am wondering how in Section #1 or  #2 I could
reformat the field value before it appears in the StackPanel.


private void FillDataGrid()
            ArrayList permitTypes = new ArrayList();
            permitTypes = control.GetSummaryTypes(currentJobID);
            if (permitTypes.Count > 0)
                for (int i = 0; i < permitTypes.Count; i++)
                    //Get the summaries for each type
                    DataView dv = control.GetSummary(currentJobID, permitTypes[i].ToString());
                    //Check to see if there are rows and if so add the Panel
                    if (dv.Table.Rows.Count > 0)
                        Expander ex1 = new Expander();
                        ex1.Header = permitTypes[i].ToString();
                        DataGrid dgList = new DataGrid();

                        ex1.Content = dgList;
                        dgList.ItemsSource = dv;

                        //Draw a line between each card dropdown expander panel
                        Line line = new Line();
                        line.X1 = 0;
                        line.X2 = ex1.ActualWidth - 1;
                        line.Y1 = 0;
                        line.Y2 = ex1.ActualHeight - 1;
                        line.Stroke = Brushes.Black ;
                        line.StrokeThickness = 2;

            public DataView GetSummary(int jobID, string permitType){
            //Set the DBCommand object
            DataSet jobDataSet = null;
            IDataParameter[] paramCollection = new IDataParameter[2];
            OleDbParameter p_JobID = new OleDbParameter("JobID", jobID);
            paramCollection[0] = p_JobID;

            OleDbParameter p_permitType = new OleDbParameter("PermitType", permitType);
            paramCollection[1] = p_permitType;

            jobDataSet = db.ExecuteDataSet(GET_SUMMARY_LIST, CommandType.Text, paramCollection);
            return jobDataSet.Tables[0].DefaultView;


   const string GET_SUMMARY_LIST = "SELECT InspectionSummary.InspectionType, InspectionSummary.Status,  " +
"InspectionSummary.Inspector,  left(InspectionSummary.InspectionSummaryDate,10) as  Dates " + 
"FROM InspectionType INNER JOIN InspectionSummary ON InspectionType.InspectionTypeName = InspectionSummary.InspectionType"  +
"WHERE InspectionSummary.JobID=@JobID AND InspectionSummary.PermitType=@PermitType ORDER BY InspectionSummary.InspectionSummaryDate;";

May 15, 2009 at 7:15 AM

This part has nothing to do with WPF even, but SQL has a REPLACE() function that should do exactly what you want (although you may need to cast the date to a string type). I believe it's even ANSI SQL.

May 15, 2009 at 7:13 PM

Yes thanks, that's what I have been using but not much success with certain types of replace.  I have to use single-quotes and I don't get the results.  I am sure there is a c# approach, I just haven't come across it yet.