Data set skip column - asp.net

I have one dataset in which i have say 10 rows..
I want to skip data of first two column means whatever data is there in that first 2 column
sholud not present in that dataset how to do this..?

What is the reason? Are you trying to do this, because you did not want it to appear in the DataGrid... Or are you trying to do some merge operations...
If for datagrid, you can just hide those columns in the DataGrid/Gridview...
If it is otherwise you can remove the columns as stated by Tim...

If you mean a Datatable instead of a dataset you can remove colums:
Dim removeCount As Int32 = 2
For i As Int32 = 1 To removeCount
For ii As Int32 = 0 To myDataTable.Columns.Count - 1
If myDataTable.Columns.CanRemove(myDataTable.Columns(ii)) Then
myDataTable.Columns.RemoveAt(ii)
Exit For
End If
Next
Next
Removes the two first columns(if they are removable and not primary keys).
Or even simpler, when removing the primary key from the datatable is acceptable:
For i As Int32 = 1 To removeCount
If Not myDataTable.Columns.CanRemove(myDataTable.Columns(0)) Then
myDataTable.PrimaryKey = Nothing
End If
myDataTable.Columns.RemoveAt(0)
Next

Related

Sqlite Update with Substring only returns first row data

I have a table (Raw_Data) with a numerical column (WorkingData).
When I test the following SELECT I return the data I require (1st digit of the numeric value)
SELECT substr([WorkingData], 1, 1) FROM Raw_Data
I now wish to take this value & insert it into another colum in the same table so I try :-
UPDATE Raw_Data SET [FirstDigit] = (SELECT substr([WorkingData], 1, 1) FROM Raw_Data)
This code uses the first digit from the first row & places that value into every row in the the FirstDigit column. Sqlite seems to interperate the SQL command as "identify the first digit of the value found in the first row in the table & use that as the FirstDigit for every subsequent value irrespective of the actual value".
eg of UPDATE comamnd results:-
Row WorkingData First Digit
1 54987 5
2 3267 5
3 19 5
Where am I going wrong with my SQL command please?
Query
UPDATE Raw_Data SET First_Digit=SUBSTR(WorkingData, 1, 1)
WHERE Raw_Data.row=Raw_Data.row;
Screen shot

DevExpress - xtragrid column running totals

I am using DevExpress xtragrid that is bound to a data source... all is fine there. I am adding 1 unbound column (balance) that will hold the result of a calculation. The 'balance' column MUST recalculate when the debit and / or credit column changes anywhere in the grid. Given there may be a large amount of records I am hoping a loop statement will not be my only option. Rather I was hoping for a solution using the
Expression editor.
example:
dr cr balance
100 0 100
0 50 50
0 45 5
Create a new column in your data source called Amount. In this column you will store both the debits and credits as positive and negative values
Add a new column to your xtragrid. Name it colRunningBalance
Set the UnboundType of the column to decimal. This tells the grid
you will be processing the data yourself
Add the following event to your form for the grid. The code is in VB.NET but it should be pretty easy to convert to any language
Private Sub gridView_CustomUnboundColumnData(sender As System.Object, e As DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs) Handles
gvCash.CustomUnboundColumnData
Dim view = DirectCast(sender, GridView)
If e.Column.FieldName = "colRunningBalance" And e.IsGetData Then
Dim total = 0D
For i As Integer = -1 To e.ListSourceRowIndex - 1
total += CDec(view.GetListSourceRowCellValue(i + 1, "Amount"))
Next
e.Value = total
End If
End Sub

ASP Format to percentage specific row of gridview

I have a fixed size table databound to a gridview from a stored procedure:
Note: the table is 17 columns long.
Currently I'm using a For..Next statement to alter the background colour of the percentage row. Can I adapt this to use DataFormatString="{0:0.0%}" instead of the backcolor attribute or should I be doing this another way?
Here's my code which currently turns the background of the row purple:
For colCount As Integer = 1 To 17
For rowCount As Integer = 1 To 1
gvAttainmentGrid.Rows(rowCount).Cells(colCount).Attributes = Drawing.Color.FromArgb(177, 160, 199)
Next
Next
EDIT
I've made some progress. I have updated my For..Next and although this displays OK on page load, when I select a different value in the control or add the element to my pre-render procedure it errors out with the message:
Input string was not in a correct format.
My code now looks like the following:
For colCount As Integer = 1 To 17
For rowCount As Integer = 1 To 1
gvAttainmentGrid.Rows(rowCount).Cells(colCount).Text = FormatPercent(Convert.ToDecimal(gvAttainmentGrid.Rows(rowCount).Cells(colCount).Text), 1)
Next
Next

How to get count of repeated values in datatable in asp.net

I want total count of repeated values in a datable.
as shown in image total count should be : 2 because repeated values are only 1 and 2.
I tried as given below:
DataView dv = new DataView(dtTemp);
int iRowCount = dv.ToTable(true, "Column1").Rows.Count;
but it returns 3 which is incorrect.
Does anyone knows how to do it.
I don't want to use loop becoz sometimes data table contains 4000-5000 rows so if we use loop it will take much more time to get the total count.
Thanks.

Randomize numbers in VB.NET without using a range i.e. Min and Max

I was wondering if anyone can point me in the right direction please? Say I am pulling the following table, I would then like to select an ID randomly. I understand how to select a random number using a Randomize() call followed by the relevant syntax but I want to pre-define the range.
i.e. Table Data
ID | Name
4345 Mike
3456 Lee
4567 John
There will be many more names but for this example you could use 3 or 4 etc..
Please help I'm starting to itch :o|
Just to make sure I understand what you want:
Given a table, you want to randomly select one of the ID values from that table.
If so, this should do it:
Dim rand As New Random()
Dim record As Integer = rand.[Next](0, myDataTable.Rows.Count)
Dim randomID As Integer = CInt(myDataTable.Rows(record)("ID"))
We have all the information we need to randomly select a row, and by extension randomly select one of the ID values in the table.
In old Vb you would do
Dim i as integer
i = (Rnd * (maxval-minval)) + minval
Since rnd returns a random number between 0 and 1 you would scale the number to the right range.

Resources