Hello VB.net Programmer; Good day Daniweb'ers;
I have a problem to my Excel Data going to DGV; Only Selected items in excel will be put in the DGV;
I don't have a database for this problem;
So here it is; This example from excel file:
1 2 3 4 5 6
A 98232 31560 80706 8357/ 33302 56999
B 98521 32470 22701 10230 20208 3993/
C 98545 31460 30701 10247 5//// 8422/
D 18630 32470 83205 20245 222// 2//03
E v=sms=sh=globe=2150
F 98653 11458 30075 20242 40127 82817
G METAR RPVD 31202
H 98618 32570 60000 PVR AQ 20202
I 98431 V=CEL=PLDT=YA
Things to be done:
1. Like I said before I don't have database.
2. This code get the first two numbers in 1st column ("98")
For Each row As DataRow In dts.Tables("[Sheet1$]").Rows
cell1 = row(0).ToString()
DataGridView1.Rows.Add(cell1.Substring(0, cell1.Length - 3), cell1.Substring(2, cell1.Length - 2))
3. Now I want to get the first two numbers in the 1st column which is ("98") but I want to ignore other row
that is not started in ("98") and ignore some blank cell.
4. Blank cell get a text "Blank" in the DGV output.
Note: 98 is like a primary key but I don't know was it possible to happen?
The code of Sir Hardz (also a Daniweb Forum Member) help me to get the first 2 numbers in 1st column and what number I need to get other number in other column;
This is the Code:
Dim cell1, cell3, col1, col2, col3, col4 As String
For Each row As DataRow In dts.Tables("[Sheet1$]").Rows
cell1 = row(0).ToString()
cell3 = row(2).ToString()
col1 = ""
col2 = ""
col3 = ""
col4 = ""
If cell1.Length = 5 Then
col1 = cell1.Substring(0, cell1.Length - 3)
col2 = cell1.Substring(2, cell1.Length - 2)
End If
If cell3.Length = 5 Then
col3 = cell3.Substring(0, cell3.Length - 4)
col4 = cell3.Substring(1, cell3.Length - 2)
End If
DataGridView1.Rows.Add(col1, col2, col3, col4)
Next
Thank you and God Bless