Matt J
asked on
VB.Net DataGridView Cell value trimming
I'm writing a program that displays a time stamp or large number in a datagrideview. I'm loading the data using a SQLite engine.
In order to convert the number (time stamp) I need to take only the first 11 characters or numbers from the value.
Is their a way to loop through all cells in a column and trim it down to say 11 characters?
In order to convert the number (time stamp) I need to take only the first 11 characters or numbers from the value.
Is their a way to loop through all cells in a column and trim it down to say 11 characters?
you should change your query and get first 11 chars
select substring(cast(timestamp as varchar), 1, 11) as timestamp,...
ASKER
Well right now, I am in the testing phase to see the best way to convert the data. What I want to do is keep the data raw as it is in the history files of web browsers. Therefor, what I am doing is allowing the user to view what is in the SQLite file but they are not able to alter it. I would like to be able to convert it as it is loaded, but I am not a SQL expert by any means.
I have tried the first two codes, and I am receiving an error that it is not set to an object reference.
I have tried the first two codes, and I am receiving an error that it is not set to an object reference.
Obviously I dont' know your DG names, adjust it where it's needed.
ASKER
The column I want to loop through is the Column 5, all cells.
what is your sql
you should change your sql and no additional code is required...
you should change your sql and no additional code is required...
ASKER
Dim connection As New SQLite.SQLiteConnection("data Source= MY DATA SOURCE")
Dim adapter As New SQLite.SQLiteDataAdapter("select * from urls", connection)
Dim table As New DataTable
Dim allhistoryItems
Dim URL As String
Dim Title As String
connection.Open()[code]
adapter.Fill(table)DataGridView1.DataSource = table
adapter.Dispose()
connection.Close()
connection.Dispose()
DataGridView1.GetCellCount
ASKER
Dim connection As New SQLite.SQLiteConnection("data Source=C:\Users\" & Environment.UserName & "\AppData\Local\Google\Chrome\User Data\Default\History")
Dim adapter As New SQLite.SQLiteDataAdapter("select * from urls", connection)
Dim table As New DataTable
Dim allhistoryItems
Dim URL As String
Dim Title As String
connection.Open()
adapter.Fill(table)
DataGridView1.DataSource = table
adapter.Dispose()
connection.Close()
connection.Dispose()
DataGridView1.GetCellCount(DataGridViewElementStates.Selected)
change that query as
and use this new column "ts" instead
* change "timestamp" to your actual column name...
select u.*, substring(cast(timestamp as varchar), 1, 11) as ts from urls u
and use this new column "ts" instead
* change "timestamp" to your actual column name...
ASKER
first you should use
this
then check column names on that line, put a breakpoint on next line
then add watch table and see what columns do you get...
after getting the column name use this query
then in your code use row("ts") instead of row(5)
if you know your column name, just update the query and use it...
this
select u.* from urls u
then check column names on that line, put a breakpoint on next line
then add watch table and see what columns do you get...
after getting the column name use this query
select u.*, substring(cast(myTSColumn as varchar), 1, 11) as ts from urls u
then in your code use row("ts") instead of row(5)
if you know your column name, just update the query and use it...
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Open in new window
Just quick example, I think you're smart enough to figure how to adjust to your own code.
This is just the first column, if you need ALL columns, add another loop inside the current one (this example is for the first 4 cols).
Open in new window
Please note, you're reading the SQL then filling the DG (first operation, what you're already doing), and now you alter the WHOLE DG (2nd operation, using my provided code). Why not input it correctly already in the first run (read value, trim, then put it in the DG)? The bigger the DG, the more inefficient it becomes, maybe even CPU/memory hogging the server/PC.