|
how do i count the rows from table in vb.net?
tell me the code..
|
|
|
|
|
Hi, try this
if you have datatable with data from your database
if datatable.rows.count > 0 then
dim couns as integert = datatable.rows.count
endif
or
in your query: select count(*) from your tablename.
Hope this one can help.
Thanks
Hi, Please select Good Question if my answer are fit to your Question.
|
|
|
|
|
I just wonder if there is any universal way to make a child form accepting values from parent form and parent form accepting values from child form. I am using visual studio 2008.
|
|
|
|
|
Use delegates to send a message from child to parent, just access methods and properties of the child from the parent.
|
|
|
|
|
thanks for your answer.
Could you please give me an example?
|
|
|
|
|
Google broken where you live ? There's an article on CP on communication between forms, I suggest you look that up, it will go into more detail than I will go into for a forum reply.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
I need some code that will search UNC paths and return a confirmation message if a specified file is found, kinda like this
if \\machinename\path\file.ext found then popup "here it is"
Is this possible?
the simpler the code is, the better
|
|
|
|
|
|
|
I can only suggest that you read up on the .NET DragDrop process. If you like MSDN documentation, start here[^].
BTW if you are going to post code samples, please use the <pre></pre> tags and paste your code between them. This preserves a lot of the formatting and makes your code a lot easier to read.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
i have an authorised SSL certificate in the web server and when client invokes the html which is present inthe server...IE should display certificate like..
Security Alert box with yes ,no and view certificate buttons.....
and what are tags i need to add in html so that client client views it when trying to access the html.....
|
|
|
|
|
And this has what to do with VB.NET??
You still haven't picked up that book, haven't you??
|
|
|
|
|
Hi all,
I have an input file that has a field named "NAME".
I have to split this Name field into PARENT and CHILD fields.
The alignement of the CHILD field is not proper, kindly bare with it...
Code I have Done:
Iam not sure whether to use IF ELSE or While Loop
I think i have to read the next line with in the If statement that i have used...
But Im not sure..;
Thanks in Advance.....
modified 28-Nov-12 8:30am.
|
|
|
|
|
I think it's a bit more complicated than deciding whether or not to use IF..ELSE or LOOP. You have more than two generations in the data i.e. ASMs contain ASMs that contain PRTs (parent-child-grandchild).
Here's some code that I've been playing with.
There is at least one bug in it but the general idea is sound (I think ).
Imports System.IO
Module Module1
Sub Main()
Call Parent_Child1("C:\PlayPen\Names.txt", "C:\PlayPen\Names_OUT.txt")
End Sub
Private Sub Parent_Child1(ByVal iFile As String, ByVal oFile As String)
Dim previousSpaces As Integer
Dim currentSpaces As Integer
Dim pF(10) As Integer
Dim parentStack(5) As String
Dim generation As Integer = 0
Dim name As String
Dim inputLine As String
Using sw As StreamWriter = New StreamWriter(oFile)
Using sa As StreamReader = New StreamReader(iFile)
inputLine = sa.ReadLine()
Call FillPF(pF, inputLine)
Call WriteHeader(sa, sw, inputLine, pF)
'Assume first data record is a parent
inputLine = sa.ReadLine()
name = inputLine.Substring(0, pF(1))
previousSpaces = NbOfCar(name, " ")
parentStack(generation) = name
'generation += 1
While sa.Peek() >= 0
inputLine = sa.ReadLine()
name = inputLine.Substring(0, pF(1))
currentSpaces = NbOfCar(name, " ")
If currentSpaces = previousSpaces Then
sw.WriteLine(parentStack(generation - 1) & name)
Else
If currentSpaces > previousSpaces Then
sw.WriteLine(parentStack(generation) & name)
previousSpaces = currentSpaces
generation += 1
parentStack(generation) = name
Else
' currentSpaces < previousSpaces
generation -= 1
previousSpaces = currentSpaces
sw.WriteLine(parentStack(generation) & name)
End If
End If
End While
End Using
End Using
End Sub
Private Function NbOfCar(ByVal s As String, ByVal c As String) As Integer
Dim i As Integer = 0
While (i < s.Length) And (s.Substring(i, 1) = c)
i += 1
End While
NbOfCar = i
End Function
Private Sub FillPF(ByVal p() As Integer, ByVal t As String)
p(0) = t.IndexOf("Nom du Modele")
p(1) = t.IndexOf("AEC_STANDARD_DESCRIPTION_FRENCH")
p(2) = t.IndexOf("AEC_FREE_DESCRIPTION_FRENCH")
p(3) = t.IndexOf("AWW_STANDARD_DESCRIPTION")
p(4) = t.IndexOf("AEC_FREE_DESCRIPTION_ENGLISH")
p(5) = t.IndexOf("AEC_ECN")
p(6) = t.IndexOf("DNF")
p(7) = t.IndexOf("BALOON")
End Sub
Private Sub WriteHeader(ByVal sr As StreamReader, ByVal sw As StreamWriter, ByVal t As String, ByVal p() As Integer)
Dim s As String = ""
s = t.Substring(p(1), p(2) - p(1)) ' desF
s = s & t.Substring(p(2), p(3) - p(2)) ' desAF
s = s & t.Substring(p(3), p(4) - p(3)) ' desA
s = s & t.Substring(p(4), p(5) - p(4)) ' desAA
s = s & t.Substring(p(5), p(6) - p(5)) ' ecn
s = s & t.Substring(p(6), p(7) - p(6)) ' dnf
s = s & t.Substring(p(7), t.Length - p(7)) ' baloon
sw.WriteLine("PARENT" & Space(10) & "CHILD" & Space(10) & s)
sw.WriteLine(sr.ReadLine()) 'The line of underscores
End Sub
End Module
It fails on the last record in this test file (and there may be other bugs.)
Nom du Modele AEC_STANDARD_DESCRIPTION_FRENCH AEC_FREE_DESCRIPTION_FRENCH AWW_STANDARD_DESCRIPTION AEC_FREE_DESCRIPTION_ENGLISH AEC_ECN DNF BALOON
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
01530501.ASM
4281484M1.PRT
3009508X1.PRT
3009508X1.PRT
3009506X1.PRT
3009506X1.PRT
3583428M1.PRT
3583428M1.PRT
3583428M1.PRT
4282884M92.ASM
4282885M2.PRT
4281478M1.PRT
4281479M1.PRT
390734X1.PRT
390734X1.PRT
390734X1.PRT
3009495X1.PRT
3009495X1.PRT
3009495X1.PRT
3385604M2.PRT
3385604M2.PRT
391039X1.PRT
4287200M3.ASM
391176X1.PRT
4281283M93.ASM
4284820M94.ASM
4282976M2.ASM
4282971M2.ASM
4285693M1.PRT
4284511M1.PRT
4284511M1.PRT
4284511M1.PRT
4284511M1.PRT
4284511M1.PRT
4284511M1.PRT
4284511M1.PRT
4284511M1.PRT
4281283XXX.ASM
You'll notice that I've dropped all the fields you were not outputting but they should be ewasy to put back in.
Hope this helps
Regards
David R
|
|
|
|
|
Here's a version that fixes the bug in previous one.
Private Sub Parent_Child1(ByVal iFile As String, ByVal oFile As String)
Dim pF(10) As Integer
Dim parentStack(5) As String
Dim generation As Integer = 0
Dim name As String
Dim inputLine As String
Using sw As StreamWriter = New StreamWriter(oFile)
Using sa As StreamReader = New StreamReader(iFile)
inputLine = sa.ReadLine()
Call FillPF(pF, inputLine)
Call WriteHeader(sa, sw, inputLine, pF)
'Assume first data record is a parent
inputLine = sa.ReadLine()
name = inputLine.Substring(0, pF(1))
parentStack(generation) = name
'Write out first record here if need to
While sa.Peek() >= 0
inputLine = sa.ReadLine()
name = inputLine.Substring(0, pF(1))
generation = GetGeneration(name)
parentStack(generation) = name
If (generation > 0) Then
sw.WriteLine(parentStack(generation - 1) & name)
Else
'Do you need to do this for lines that have no parent?
sw.WriteLine(parentStack(generation))
End If
End While
End Using
End Using
End Sub
Private Function GetGeneration(ByVal s As String) As Integer
Dim g As Integer
g = NbOfCar(s, " ")
If (g > 1) Then
g = (g - 1) / 2
End If
GetGeneration = g
End Function
It assumes that the first child generation has 3 spaces; the second has 5 spaces,; the third has 7 spaces and so on. If that's not the case then GetGeneration() might have to be modified.
You'll notice it is a bit different from my original effort. That's because I put my thinking head on and realised that the number of spaces tells you the generation and the parent must be the previous generation!
Regards
David R
|
|
|
|
|
|
I thought this might be the case. As I said this means modifying GetGeneration().
Here's a version that should work.
Private Function GetGeneration(ByVal s As String) As Integer
Dim spaceCount As Integer
Static maxSpaces As Integer = -1
Static lastGen As Integer = -1
Static genDict As Dictionary(Of Integer, Integer) = New Dictionary(Of Integer, Integer)
spaceCount = NbOfCar(s, " ")
If (spaceCount > maxSpaces) Then
lastGen += 1
genDict.Add(spaceCount, lastGen)
maxSpaces = spaceCount
End If
GetGeneration = genDict(spaceCount)
End Function
You also need to modify the Parent_Child1 sub to add the line in bold as below.
'Assume first data record is a parent
inputLine = sa.ReadLine()
name = inputLine.Substring(0, pF(1))
generation = GetGeneration(name)
parentStack(generation) = name
'Write out first record here if need to
I've not fully tested this but it seems ok on a modified version of the test file I sent in previous post.
Regards
David R
|
|
|
|
|
The code reads the input file and writes to the output file.
But not for the entire file.
Giving error message after few lines written..;
I'm getting this error message "The key data were missing from the dictionary." in the line below:
GetGeneration = genDict(spaceCount)
|
|
|
|
|
I suspect this means the spacing in the data file is inconsistent.
My solution assumes that in a file all children have same number of spaces; all grand-children have same number of spaces; all great-grand-children have same number of spaces and so on. With number of spaces increasing for younger generations.
If the spacing is inconsistent then the dictionary approach will fail and the problem is more complex.
Off the top of my head I don't have a solution but think it probably means constructing some sort of tree to hold the data.
Regards
David R
|
|
|
|
|
I just had a thought about my last version of GetGeneration(). It works if the spacing in a file is consistent but if you call Parent_Child1 multiple times in a program (with different input files) it will fail unless the files have the same spacing.
So here's a version that should fix that potential bug.
Private Function GetGeneration(ByVal s As String, ByVal resetDict As Boolean) As Integer
Dim spaceCount As Integer
Static maxSpaces As Integer = -1
Static lastGen As Integer = -1
Static genDict As Dictionary(Of Integer, Integer) = New Dictionary(Of Integer, Integer)
If (resetDict) Then
genDict.Clear()
maxSpaces = -1
lastGen = -1
End If
spaceCount = NbOfCar(s, " ")
If (spaceCount > maxSpaces) Then
lastGen += 1
genDict.Add(spaceCount, lastGen)
maxSpaces = spaceCount
End If
GetGeneration = genDict(spaceCount)
End Function
In ParentChild1 set the second parameter to True on the first call (before the While loop) and to False for the call in the While loop.
Regards
David R
|
|
|
|
|
There are 2 parameters in genDict
Static genDict As Dictionary(Of Integer, Integer) = New Dictionary(Of Integer, Integer)
But while calling genDict there is only on parameter...
GetGeneration = genDict(spaceCount)
I think there is some problem here, if im not wrong...
suggest your comment about this case..;
Thanks in advance
|
|
|
|
|
Not a problem. Have a look at the Dictionary(Of Tkey, Tvalue) class in help.
What I'm doing is storing the number of spaces (as key) and the generation (as value) so given the number of spaces I can look up the generation.
I tried running my program using the data in your last reply and cannot recreate the problem.
(Edited out the commented lines.
Here's the output I got.
PARENT CHILD AEC_STANDARD_DESCRIPTION_FRENCH AEC_FREE_DESCRIPTION_FRENCH AWW_STANDARD_DESCRIPTION AEC_FREE_DESCRIPTION_ENGLISH AEC_ECN DNF BALOON
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
01260709.ASM 4296458M91.ASM
01260709.ASM 4296454M1.ASM
4296454M1.ASM COVER_DISTRIB_74L_SRT2_2.ASM
COVER_DISTRIB_74L_SRT2_2.ASM 837070162_LRT.PRT
COVER_DISTRIB_74L_SRT2_2.ASM BRACKETPLATEWITHOUTAIRB.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 836667411_32_4DEG_ASM_2XXX.ASM
836667411_32_4DEG_ASM_2XXX.ASM DAYCO_BELTTENSIONER_BASE_2XXX.PRT
836667411_32_4DEG_ASM_2XXX.ASM DAYCO_BELTTENSIONER_ARM_3XXX.PRT
836667411_32_4DEG_ASM_2XXX.ASM DAYCO_BELTTENSIONER_RING_2XXX.PRT
836667411_32_4DEG_ASM_2XXX.ASM 836866321_2XXX.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529801470_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529801540_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529801540_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
COVER_DISTRIB_74L_SRT2_2.ASM 529401440_LRT04012006.PRT
01260709.ASM 4282023M91.ASM
4282023M91.ASM 4282024M1.PRT
4282023M91.ASM 1619032M1.PRT
Regards
David R
|
|
|
|
|
|
As I thought the file has inconsistent spacing.
This extract is where the problem begins.
4282023M91.ASM ENS. VOLANT MOTEUR
4282024M1.PRT VOLANT D'INERTIE
1619032M1.PRT COURONNE DEMARREUR
4282010M1.PRT --
3786094M93.ASM ENS DEMARREUR ISKRA
3823621M94.PRT DEMARREUR ISKRA
Both 4282023M91.ASM and 4282010M1.PRT are at Child level (generation 1) but the number of spaces is 5 and 3.
When the dictionary is populated in GetGeneration() the assumption is that all Child level names will have the same number of spaces in front, and their children will have more spaces. So there is no entry corresponding to 3 spaces.
Also, 3823621M94.PRT is a Grand-Child (generation 2), but has 5 spaces i.e. same as Child so if a look up is done in the dictionary it gets the wrong parent (01260709.ASM instead of 3786094M93.ASM).
I can't think of an easy way to fix this.
How are the files created? Is it possible to ensure that the creation processes produce files with consistent spacing? They don't have to have the same spacing in every file but each file must have consistent spacing for my code to work. Failing that it's back to the drawing board.
Regards
David R
|
|
|
|
|