|
No, I don't believe so.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I cannot figure out why this doesn't work. Everythign says it should... I'm trying to see if a datagridviewrow contains DBNUll
'first = IIf(TypeOf _row.Cells(1).Value Is DBNull, 0, CDec(_row.Cells(1).Value))
'second = IIf(TypeOf _row.Cells(2).Value Is DBNull, 0, CDec(_row.Cells(2).Value))
'final = IIf(TypeOf _row.Cells(3).Value Is DBNull, 0, CDec(_row.Cells(3).Value))
I GET ERRORS!!!
But if I do this, not only is it ugly as heck but it works!!
If (TypeOf _row.Cells(1).Value Is DBNull) Then
first = 0
Else
first = _row.Cells(1).Value
End If
If (TypeOf _row.Cells(2).Value Is DBNull) Then
second = 0
Else
second = _row.Cells(2).Value
End If
If (TypeOf _row.Cells(3).Value Is DBNull) Then
final = 0
Else
final = _row.Cells(3).Value
End If
Why?!?! I'm so angry. I have tried everything from
IsDBNull(value)
to
value Is DbNull
value Is DbNull.Value
to
value is typeof(DbNull)
Its just frustating.. am I doing something wrong here or is this just a flaw?
|
|
|
|
|
Yah I knew I used it somewhere, try
mvLogID = IIf(IsDBNull(oRow("LogID")), 0, oRow("LogID"))
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
No luck. I'm not trying to find if a row is null, just if a cell is null
first = IIf(IsDBNull(_row.Cells(1)), 0, CDec(_row.Cells(1).Value))
second = IIf(IsDBNull(_row.Cells(2)), 0, CDec(_row.Cells(2).Value))
final = IIf(IsDBNull(_row.Cells(3)), 0, CDec(_row.Cells(3).Value))
Using the name instead of the index doesn't work either.
Still get "Conversion from DBNull to type Decimal is not valid"
|
|
|
|
|
Can I have my foot back now please I was testing against a DATAROW.
Try, you are testing the cell, it will always be there. And here is your foot
first = IIf(IsDBNull(_row.Cells(1).Value), 0, CDec(_row.Cells(1).Value))
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Lol
Still no luck though. Here it is:
(All of it)
For Each _row As DataGridViewRow In dgvGrades.Rows
Dim first, second, final As Decimal
' ********* This doesnt not seem to work but technically it should **************
' ********* Must be a FLAW in VB.net :-) lol ************
'first = IIf(TypeOf _row.Cells(1).Value Is DBNull, 0, CDec(_row.Cells(1).Value))
'second = IIf(TypeOf _row.Cells(2).Value Is DBNull, 0, CDec(_row.Cells(2).Value))
'final = IIf(TypeOf _row.Cells(3).Value Is DBNull, 0, CDec(_row.Cells(3).Value))
first = IIf(IsDBNull(_row.Cells(1).Value), 0, CDec(_row.Cells(1).Value))
second = IIf(IsDBNull(_row.Cells(2).Value), 0, CDec(_row.Cells(2).Value))
final = IIf(IsDBNull(_row.Cells(2).Value), 0, CDec(_row.Cells(3).Value))
Dim _average As Decimal = (first + second + 2 * final) / 4
For Each _sRow As DataGridViewRow In dgvStudents.Rows
If _row.Cells(0).Value Is Nothing Then
Exit For
Else
If _row.Cells(0).Value = _sRow.Cells(0).Value Then
dgvAverage.Rows.Add(New Object() {_sRow.Cells(2).Value.ToString() + " " + _sRow.Cells(1).Value.ToString(), _average.ToString(), CalculateGrade(_average), IIf(_average > 59, True, False)})
Exit For
End If
End If
Next
Next
The funny thing is (well not so funny) is that I can do this:
If IsDBNull(_row.Cells(1).Value) Then
MessageBox.Show("IT IS NULL!")
End If
AND IT WORKS! its the same thing!
|
|
|
|
|
you said "you get errors". what error are you getting?
btw...not sure if you meant to do this but you are testing cell 2 again and then useing cell 3
final = IIf(IsDBNull(_row.Cells(2).Value), 0, CDec(_row.Cells(3).Value))
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
The error is it can't convert dbnull to decimal. It shouldn't be trying because it's supposed to make it 0 if it was dbnull. Yeah I didn't mean to do that I just changed it so much trying to get it to work I messed that up
|
|
|
|
|
I have seen that somestimes checking for dbnull in an IIF doesn't always work. try breaking it out into a normal IF/Else statement.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Well I know that it works fine with a bunch of if then statements.
I was trying to figure out if it was something I was doing why the IIf wasn't working. But its starting to look more like a flaw with VB.net. Using the IIf statements looks much cleaner and less code to me. But if it just won't work with comparing DBNull values.. then what can I do lol
|
|
|
|
|
ya it's a bug...
you can get the same effect by writing a function that will act like the IIF so you'll get the clean look but the function will use the full if/then/else...
't = true part of iif / e = else part of iif
public function MyIIF (b as boolean, t as object, e as object) as object
you can of course overload that to do type-safe checks
public function MyIIF (b as boolean, t as string, e as string) as object
public function MyIIF (b as boolean, t as integer, e as integer) as object
etc
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Ok Thanks for your help
|
|
|
|
|
If you're using VB9 there is an overload for the If keyword that solves this problem.
Instead of IIf try just using If
|
|
|
|
|
When using IIF both the true and the false portions are evaluated before the IIF test is done.
using the If construct only the true portion is evaluated after the IF test is done and the false portion is never evaluated if the test is true.
|
|
|
|
|
Hi
In my app i have to read thousands of lines of data written in a
text file.
I have saved the lines previously.
The size of text file is 50 MB.
My problem is that it takes a lot of time to read that.
If i save the lines in a database, would the 'reading' be faster?
TheMrProgrammer
http://www.icbse.com/2009/funny-exam-answers-school-students
http://download.cnet.com/TheCalcMan/3000-2094_4-10958266.html
|
|
|
|
|
Hi,
I very much doubt reading 50MB of data is taking very long, it should be possible to do that in say 1 second. If your app is slower at it, it probably is due to what it is you do with the data, such as adding it to some of the GUI controls. Tell us more, and show some relevant code.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi Luc,
Thanks for reply.
Yes I do more than reading.
I read the file.
Dim s$ = my...readalllines(myfile.txt)
There are sentences separated by # which I transfer in an array
so that one sentence get into one element of array
using simple code of 6 lines.
This operation I do in the variable s.
that's all I do.
The size of the testing file is 10 MB and it takes about 4 min and 24 s
The size of real file is nearly 50 MB.
So what do you suggest now?
TheMrProgrammer
http://www.icbse.com/2009/funny-exam-answers-school-students
http://download.cnet.com/TheCalcMan/3000-2094_4-10958266.html
|
|
|
|
|
Prankur Rusia wrote: So what do you suggest now?
Huh? The same as I suggested some 10 hours ago. You haven't given any new facts.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi
I got the answer to my question.
The file gets read quickly but the sorting in to the array takes time.
There one thing I would like to ask you.
The basic purpose of this is to search within the text file for a word.
As there can be multiple occurrences of that word I first put the sentences,
sentence by sentence, into an array.
Then I search the array element by element to find the word by looping through the array.
Now if I use the database, I would have access to the data already sorted
sentence-wise.
Then I just need to loop the database to search.
Now I wanted to ask you, if I use the above defined process, will it be
faster?
Is the algorithm I am following is an efficient one?
I know you are a busy man.
But please spare a minute and tell me.
Thanks.
TheMrProgrammer
http://www.icbse.com/2009/funny-exam-answers-school-students
http://download.cnet.com/TheCalcMan/3000-2094_4-10958266.html
|
|
|
|
|
I can do that in a fast way with or without a database.
And everyone can come up with a slow implementation with or without a database. Getting it slow with a database is harder to achieve, since there is less code to mess with.
FYI: de database has to read the data from disk too, and search your string too, so why would it really be faster?
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Dear Members,
I have a datagridview in windows form. In this grid one column is datagridviewcheckboxcolumn. when i select the first checkbox and i click a save button in toolstrip it will not work. But the same code in command button it is worked. Please check the following code
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim arr As New ArrayList
Dim en As New TestEnity
en.Name = "name1"
arr.Add(en)
en = New TestEnity
en.Name = "name2"
arr.Add(en)
dgTest.DataSource = arr
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each row As DataGridViewRow In Me.dgTest.Rows
Dim checkBoxCell As DataGridViewCheckBoxCell = TryCast(row.Cells("dgvSelected"), DataGridViewCheckBoxCell)
If checkBoxCell IsNot Nothing Then
Dim checked As Boolean = CType(checkBoxCell.Value, Boolean)
If checked Then
MessageBox.Show("Row : " & row.Index & "Checked")
Else
MessageBox.Show("Row : " & row.Index & "Not Checked")
End If
End If
Next
End Sub
Private Sub SaveToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click
For Each row As DataGridViewRow In Me.dgTest.Rows
Dim checkBoxCell As DataGridViewCheckBoxCell = TryCast(row.Cells("dgvSelected"), DataGridViewCheckBoxCell)
If checkBoxCell IsNot Nothing Then
Dim checked As Boolean = CType(checkBoxCell.Value, Boolean)
If checked Then
MessageBox.Show("Row : " & row.Index & "Checked")
Else
MessageBox.Show("Row : " & row.Index & "Not Checked")
End If
End If
Next
End Sub
End Class
Public Class TestEnity
Dim _Name$
Public Property Name()
Get
Return _Name
End Get
Set(ByVal value)
_Name = value
End Set
End Property
sree
|
|
|
|
|
ToolstripMenu's Forms will be your MDI-Parent, and datagridview is in mdi_child, So you have to call by form5.My_Save()
So put your save-codes inside a sub and call it from mdi_parent as I gave.
|
|
|
|
|
I use a webservice to import the xml into a ms access database, and interop code is not working.
This is my code so far, but it is not working properly.
im strConnection As String
Dim objDataSet As New DataSet()
Dim objConnection As OleDbConnection
Dim objAdapter As OleDbDataAdapter
Dim intI As Integer
Dim ds As New DataSet
Dim streamRead As New System.IO.FileStream("C:\NTB100514_07_22_2009_225551.xml", System.IO.FileMode.Open)
ds.ReadXml(streamRead)
streamRead.Close()
If ds.Tables.Count > 0 Then
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & "c:\PC Auditer.accdb"
objConnection = New OleDbConnection(strConnection)
objConnection.Open()
objAdapter = New OleDbDataAdapter()
Dim cb As New OleDbCommandBuilder(objAdapter)
For intI = 0 To ds.Tables.Count - 1
If ds.Tables(intI).Rows.Count > 0 Then
DataGridView1.DataSource = ds.Tables(intI)
objAdapter.SelectCommand = New OleDbCommand("SELECT * FROM [" + ds.Tables(intI).TableName + "] ", objConnection)
objAdapter.Fill(ds, ds.Tables(intI).TableName.ToString)
objAdapter.UpdateCommand = cb.GetUpdateCommand()
objAdapter.Update(ds, ds.Tables(intI).TableName.ToString)
End If
Next
objConnection.Close()
End If
In my access database all the primairy keys and relationships are defined. The first time (intI=0) the update command works well, but the second time (intI=1) iI get an error.
Kind regards,
Jurgen
ps: I am a beginner, so excuse me if my code is lokking so nice.
|
|
|
|
|
What is the error ? Have you stepped through in the debugger to see what is happening ? What line has the error ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi Christian,
The error is in line: objAdapter.Update(ds, ds.Tables(intI).TableName.ToString)
"Missing the DataColumn 'ID' in the DataTable 'Shares' for the SourceColumn 'ID'"
I don't have a datacolumn 'ID' in my table Shares. I think it has to do with the
primairy key and referential integrety. The previous table 'SOS' has a column ID (primairy key)
which has a relation with the column 'ID-Share' from table 'Shares'.
Kind regards,
Jurgen
|
|
|
|