I have a GridView connected to my database through an sql data source. It is bound by the follow code:
firstview = "SELECT ID, DC, DD, CYM, CB, ST FROM SCH_SCHEMANAME.TABLENAME WHERE CI = " & txtboxvalue.text & " AND ST = 'whatever' AND D = 0"
SqlDataSource1.SelectCommand = firstview
GridView1.DataBind()
There is no problem connecting to the database. Inside the database, one of the column contains extra whitespace. To make a long story short, the DD column is a short sentence that contains more than one space between some words. e.g. "This_is____a_sentence_stored___in_the_____dd_column" where each underscore is a space in this example.
When I do the databind, the spaces in between the words are all reduced to 1 space. I do, however, need to keep the exact amount of spaces between each word when the data is bound in the GridView. At the moment, it is showing in the GridView as "This_is_a_sentence_stored_in_the_dd_column" but I want to keep the amount of spaces rather than have them automatically cut down.
Can anyone help?
I was able to fix by doing the following on the RowDataBound event for the gridview.
e.Row.Cells(4).Text = e.Row.Cells(4).Text.Replace(" ", " ")
The database was retrieving the correct value, but the spaces were being parsed/encoded. JPW's links helped me with the line of code.
Thanks
It is not about a database. The browser treats multiple spaces as one. E.g. see several workarounds here: http://www.codeproject.com/Articles/30740/Avoid-Multiple-Space-Elimination-in-ASP-NET-GridVi
Related
I have a data table that is loaded from an excel spreadsheet, which works fine. I then want to remove the duplicates from the table, which I can also accomplish. Next I want to add new rows which is where the whole thing goes wonky. The code runs and no errors are returned. (I have Try/Catch statements in place and they never get triggered).
Here is the code that tries to add the new row to the data table.
newDRow = dtTemp.NewRow
newDRow("QTY") = Convert.ToInt32(dupList(1))
newDRow("GRATING-ID") = newMarkNum
newDRow("GRATING SPAN DECIMAL INCHES") = Convert.ToDecimal(dupList(2))
newDRow("GRATING WIDTH DECIMAL INCHES") = Convert.ToDecimal(dupList(3))
Try
dtTemp.Rows.Add(newDRow)
Catch ex As Exception
message = HttpUtility.JavaScriptStringEncode(ex.Message)
End Try
The data table is called dtTemp. I have put break points in and can verify that each of the new row columns are getting the correct data.
The original data table is being passed to this function as follows:
Private Function RemoveDuplicate(ByVal dtInput As DataTable) As DataTable
I have a line that copies the dtInput table to the dtTemp table like so:
Dim dtTemp As DataTable = dtInput.Copy()
I just can't seem to find out why the row insert is not working. When the function runs and the data grid view is populated I see the results of removing the duplicate lines but the new lines are not in the table.
Any ideas?
Update #1--------------
I checked the table contents after the inserts were supposed to have happened but they do not show up. there should be a line that says:
2|1121-G31|32.875|42
And a line that says
7|1185-G33|22|22
But they are not there.
So I figured out what stupid mistake I was doing.
I had my new data row statement OUTSIDE of the For loop that was adding the new rows to the data table.
Moved it inside the for loop and it works great now!
I have created a report from the following query
SELECT TasksEntries.Project, TasksEntries.Task, Sum(TimeTracker.WorkHours) AS
TotalHours
FROM TasksEntries INNER JOIN TimeTracker
ON (TasksEntries.EmployeeId = TimeTracker.EmployeeId) AND (TasksEntries.TaskID
= TimeTracker.TaskId)
GROUP BY TasksEntries.Project, TasksEntries.Task;
The start and end dates are captured from a form and passed like shown below. WorkDate is a column in the TimeTracker table and is not present in any other table.
strWhere = "WorkDate BETWEEN #" & txtMgrRptStartDate & "# AND #" &
txtMgrRptEndDate & "#"
DoCmd.OpenReport "rptTotalProjectHours", acViewPreview,
"qryTotalProjectHours", strWhere, acWindowNormal
When the report is invoked, I get a box where it says
"Enter parameter value" for Workdate.. I am unsure why I get that.
The query runs fine when I run it separately with the start and end dates hard coded in there. The problem seems to occur only when it is passed through the docmd.openreport. Can someone help me get to the bottom of this? When passing the WorkDate thru the OpenReport, is it mandatory that the column name be present in the SELECT statement?
Appreciate your help in advance.
I solved it by including the date criteria in the WHERE clause of the SELECT statement and specifying the form text box names of start and end dates.
The other thing that I did was to eliminate the query name from the Docmd.openreport since the report was created from the named query.
I have listbox with text in it, and I was asked to see if I could just justify its contents after the dash. My resulting code produced something like this:
Which works fine for scenarios where the text to the left of the dash is less than the max length found from the other items in the listbox (i.e. (B20) is less than (B15-B19), which is the longest entry found, so add some whitespace before the dash).
The issue, though, is that if the text before the dash is same length, it still looks like it isn't justified. Example:
Is there a way to truly line up all the dashes? I would imagine I would have to look at the actual pixel length of the characters before the dash as opposed to the length?
Notes:
I am using ASP.NET Webforms
VB.NET
The text for each item in the listbox is all one string
Right now, my method to accomplish what you see in the first picture is as follows:
Public Sub JustifyDisplayName()
Const ACCOUNT_FOR_DASH As Integer = 4
Dim maxCharCount As Integer = 0
Dim whiteSpace As String = HttpUtility.HtmlDecode(" ")
'Find which one is the longest code
For Each element As TextEntry In Me
If element.Value.Length > maxCharCount Then
maxCharCount = element.Value.Length
End If
Next
'Now, extend the '-' to the max for all items
For Each element As TextEntry In Me
'See how much white space we need to inject
Dim paddingNeeded As Integer = maxCharCount - element.Value.Length
Dim tempDisplay As StringBuilder = New StringBuilder(element.Value)
If paddingNeeded > 0 Then
tempDisplay.Append(CChar(whiteSpace), paddingNeeded + ACCOUNT_FOR_DASH)
tempDisplay.Append(" - " & element.Description)
End If
tempDisplay.Append(" - " & element.Description)
element.DrillDownDisplayNameJustified = tempDisplay.ToString()
Next
End Sub
Thanks.
If you used a fixed-width font, you could make this all much easier. In addition to good ol' Courier, I believe there are others.
If you don't, you're not going to be able to get exactly the right width. You could get close, but you won't get it exactly, because the difference in length between (H60-H95) and (I00-I99) as they are rendered may not evenly divide into increments of one .
But if you really want to give this a try, you'll have to use the System.Drawing namespace, the Graphics class, and a method on Graphics called MeasureString. This will be just to get the lengths of the strings in your selected font, though: System.Drawing doesn't apply to web apps.
If you could append spaces to short items before the dash so that you always have the same number of characters before the dash, you may consider using Monospaced Fonts, where each character occupies the same width - Ref: Similar Question.
I'm importing an .xls file using the following connection string:
If _
SetDBConnect( _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filepath & _
";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""", True) Then
This has been working well for parsing through several Excel files that I've come across. However, with this particular file, when I SELECT * into a DataTable, there is a whole column of data, Item Description, missing from the DataTable. Why?
Here are some things that may set this particular workbook apart from the others that I've been working with:
The workbook has a freeze pane consisting of the first 24 rows (however, all of these rows appear in the DataTable)
There is some weird cell highlighting going on throughout the workbook
That's pretty much it. I can't see anything that would make the Item Description column not import correctly. Its data is comprised of all Strings that really have no special characters apart from &. Additionally, each data entry in this column is a maximum of 20 characters. What is happening? Is there any other way I can get all of the data? Keep in mind I have to use the original file and I cannot alter it, as I want this to ultimately be an automated process.
Thanks!
Some initial thoughts/questions: Is the missing column the very first column? What happens if you remove the space within "Item Description"? Stupid question, but does that column have a column header?
-- EDIT 1 --
If you delete that column, does the problem move to another column (the new index 4), or is the file complete. My reason for asking this -- is the problem specific to data in that column/header, or is the problem more general, on index 4.
-- EDIT 2 --
Ok, so since we know it's that column, we know it's either the header, or the rows. Let's concentrate on rows for now. Start with that ampersand; dump it, and see what happens. Next, work with the first 50% of rows. Does deleting that subset affect anything? What about the latter 50% of rows? If one of those subsets changes the result, you ought to be able to narrow it down to an individual row (hopefully not plural) by halfing your selection each time.
My guess is that you're going to find a unicode character or something else funky is one of the cells. Maybe there's a formula or, as you mentioned, some of that "weird cell highlighting."
It's been years since I worked with excel access, but I recall some problems with excel grouping content into some areas that would act as table inside each sheet. Try copy/paste the content from the problematic sheet to a new workbook and connect to that workbook. If this works you may be able to investigate a bit further about areas.
How to show two records for given single search?
UI page contains millions of records.I need to show only two records instead of giving
single search.
using OR SEARCH or whatever use.I want to show two records.
And how can i give two values in single text box?
That dependa on you only, you can make use of some special charater to break two string like : or | so that you allow to etner two string like "abc|5678" than in back end you break this string in two string string1 = abc and string2=5678
Two values in single text box:
txt.Text = "value1" + "value2";