|
OK, for those poor unfortunate souls who are having this same problem as me, here are the steps I've done so far to remedy:
1) Use the nulldatetimepicker extension shown here: http://www.codeproject.com/KB/selection/NullableDateTimePicker.aspx[^]
and if you're using VB, convert it with this: http://www.developerfusion.com/tools/convert/csharp-to-vb/[^]
2) open the .xsd file of your dataset and manually change the msprop:nullValue="_throw" property of any datetime field to msprop:nullValue="_null". Be aware: every so often the designer will decide to just omit the datetime fields because it's caught on to your treacherous workaround of Microsoft's poor design; and that just cannot be allowed. :P If that happens just go to the designer again and set the fields as (throw exception), save, close, and follow this step again.
This seems to work just fine for existing records. You can re-null datetime fields and successfully update. The only thing I'm having trouble with is inserting new records. I always get:
{"Failed to convert parameter value from a Int32 to a DateTime."}
{"Invalid cast from 'Int32' to 'DateTime'."}
...which is baffling me, but I'm still trying to research, debug, reinvent the wheel for. I'll keep posting as I figure it out.
Here is my entire "add record" sub:
Private Sub AddBranchToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddBranchToolStripButton.Click
If PermissionsMode = "ReadWrite" Then
Dim MainID As String = "0"
Dim OrgName As String = "Error"
'Set the OrgRowIsAdding flag to true so that the AutoSave feature doesnt try to save a row with blank data
OrgRowIsAdding = True
'record the main loc ID and org name
MainID = ParentOrgIDTextBox.Text
OrgName = OrganizationTextBox.Text
'Actually add the branch
Try
If Me.OrganizationsBindingSource.AddNew() IsNot Nothing Then
OrganizationTextBox.Text = OrgName
ParentOrgIDTextBox.Text = MainID
MemberStatusComboBox.SelectedValue = "Branch"
MemberTypeComboBox.SelectedValue = "Branch"
Me.Text = "[Branch] " & OrgName
OrgRowIsAdding = False
SetFormControls(True, True)
Else
MsgBox(My.Settings.OrganizationsFrmAddRecGenErrorMsg, MsgBoxStyle.Exclamation, "Error Adding Record")
GoTo skipaddbranch
End If
Catch ex As Exception
Throw New Exception("Branch Location Add Failed", ex)
GoTo skipaddbranch
End Try
Else
MsgBox(My.Settings.StdDenyWriteError, MsgBoxStyle.Exclamation, "Access Denied")
GoTo skipaddbranch
End If
skipaddbranch:
OrgRowIsAdding = False
Exit Sub
End Sub
/rant_at_microsoft
Am I just crazy or is it too much to ask of Microsoft to support the SQL datatype in full in their own development application? They wrote SQL 2005, and they wrote Visual Studio 2008.
This problem is driving me nuts. Yeah i know, i know...most people claim it has something to do with SQL/Visual Studio versions not being exactly on par, but really I've found posts on this same topic concerning VS 2005!!! So personally, I don't buy it. Additionally, you've been able to null datetime fields in SQL for a while now, so to me this is just plain old negligence on Microsoft's part. Get it together Microsoft!
/endrant
/rant_at_everyone
Am I to understand that every single programmer that uses Visual Studio simply accepts the workaround to use date.mindate as a replacement for null???? I guess I just can't accept that. I'm determined to figure this out.
/endrant_at_everyone
More to come....
|
|
|
|
|
Update:
Still nothing. I've even set my code to set any Null date to 1/1/1900 even though I really didnt want to do that. When I add a new record, no matter what, when i try to save back to the DB, I always get:
"Invalid cast from 'Int32' to 'DateTime'."
It shows the exception originates in the automatically generated "UpdateAll" Sub created by the dataset designer. Here is the code just before where the exception occurs:
Try
'---- Prepare for update -----------
'
If (Not (Me._employeesTableAdapter) Is Nothing) Then
revertConnections.Add(Me._employeesTableAdapter, Me._employeesTableAdapter.Connection)
Me._employeesTableAdapter.Connection = CType(workConnection,Global.System.Data.SqlClient.SqlConnection)
Me._employeesTableAdapter.Transaction = CType(workTransaction,Global.System.Data.SqlClient.SqlTransaction)
If Me._employeesTableAdapter.Adapter.AcceptChangesDuringUpdate Then
Me._employeesTableAdapter.Adapter.AcceptChangesDuringUpdate = false
adaptersWithAcceptChangesDuringUpdate.Add(Me._employeesTableAdapter.Adapter)
End If
End If
If (Not (Me._organizationMemosTableAdapter) Is Nothing) Then
revertConnections.Add(Me._organizationMemosTableAdapter, Me._organizationMemosTableAdapter.Connection)
Me._organizationMemosTableAdapter.Connection = CType(workConnection,Global.System.Data.SqlClient.SqlConnection)
Me._organizationMemosTableAdapter.Transaction = CType(workTransaction,Global.System.Data.SqlClient.SqlTransaction)
If Me._organizationMemosTableAdapter.Adapter.AcceptChangesDuringUpdate Then
Me._organizationMemosTableAdapter.Adapter.AcceptChangesDuringUpdate = false
adaptersWithAcceptChangesDuringUpdate.Add(Me._organizationMemosTableAdapter.Adapter)
End If
End If
If (Not (Me._peopleTableAdapter) Is Nothing) Then
revertConnections.Add(Me._peopleTableAdapter, Me._peopleTableAdapter.Connection)
Me._peopleTableAdapter.Connection = CType(workConnection,Global.System.Data.SqlClient.SqlConnection)
Me._peopleTableAdapter.Transaction = CType(workTransaction,Global.System.Data.SqlClient.SqlTransaction)
If Me._peopleTableAdapter.Adapter.AcceptChangesDuringUpdate Then
Me._peopleTableAdapter.Adapter.AcceptChangesDuringUpdate = false
adaptersWithAcceptChangesDuringUpdate.Add(Me._peopleTableAdapter.Adapter)
End If
End If
If (Not (Me._organizationsTableAdapter) Is Nothing) Then
revertConnections.Add(Me._organizationsTableAdapter, Me._organizationsTableAdapter.Connection)
Me._organizationsTableAdapter.Connection = CType(workConnection,Global.System.Data.SqlClient.SqlConnection)
Me._organizationsTableAdapter.Transaction = CType(workTransaction,Global.System.Data.SqlClient.SqlTransaction)
If Me._organizationsTableAdapter.Adapter.AcceptChangesDuringUpdate Then
Me._organizationsTableAdapter.Adapter.AcceptChangesDuringUpdate = false
adaptersWithAcceptChangesDuringUpdate.Add(Me._organizationsTableAdapter.Adapter)
End If
End If
If (Not (Me._cSISelections2004TableAdapter) Is Nothing) Then
revertConnections.Add(Me._cSISelections2004TableAdapter, Me._cSISelections2004TableAdapter.Connection)
Me._cSISelections2004TableAdapter.Connection = CType(workConnection,Global.System.Data.SqlClient.SqlConnection)
Me._cSISelections2004TableAdapter.Transaction = CType(workTransaction,Global.System.Data.SqlClient.SqlTransaction)
If Me._cSISelections2004TableAdapter.Adapter.AcceptChangesDuringUpdate Then
Me._cSISelections2004TableAdapter.Adapter.AcceptChangesDuringUpdate = false
adaptersWithAcceptChangesDuringUpdate.Add(Me._cSISelections2004TableAdapter.Adapter)
End If
End If
'
'---- Perform updates -----------
'
If (Me.UpdateOrder = UpdateOrderOption.UpdateInsertDelete) Then
result = (result + Me.UpdateUpdatedRows(dataSet, allChangedRows, allAddedRows))
result = (result + Me.UpdateInsertedRows(dataSet, allAddedRows))
Else
result = (result + Me.UpdateInsertedRows(dataSet, allAddedRows))
result = (result + Me.UpdateUpdatedRows(dataSet, allChangedRows, allAddedRows))
End If
result = (result + Me.UpdateDeletedRows(dataSet, allChangedRows))
'
'---- Commit updates -----------
'
workTransaction.Commit
If (0 < allAddedRows.Count) Then
Dim rows((allAddedRows.Count) - 1) As Global.System.Data.DataRow
allAddedRows.CopyTo(rows)
Dim i As Integer = 0
Do While (i < rows.Length)
Dim row As Global.System.Data.DataRow = rows(i)
row.AcceptChanges
i = (i + 1)
Loop
End If
If (0 < allChangedRows.Count) Then
Dim rows((allChangedRows.Count) - 1) As Global.System.Data.DataRow
allChangedRows.CopyTo(rows)
Dim i As Integer = 0
Do While (i < rows.Length)
Dim row As Global.System.Data.DataRow = rows(i)
row.AcceptChanges
i = (i + 1)
Loop
End If
Catch ex As Global.System.Exception
workTransaction.Rollback
'---- Restore the dataset -----------
If Me.BackupDataSetBeforeUpdate Then
Global.System.Diagnostics.Debug.Assert((Not (backupDataSet) Is Nothing))
dataSet.Clear
dataSet.Merge(backupDataSet)
Else
If (0 < allAddedRows.Count) Then
Dim rows((allAddedRows.Count) - 1) As Global.System.Data.DataRow
allAddedRows.CopyTo(rows)
Dim i As Integer = 0
Do While (i < rows.Length)
Dim row As Global.System.Data.DataRow = rows(i)
row.AcceptChanges
row.SetAdded
i = (i + 1)
Loop
End If
End If
Throw ex
Finally
That "ex" exception is thrown and I get the error above. There are no Int32's being cast to datetime. all int32's are int32's and all datetime's are datetime's...what in the heck is happening?
|
|
|
|
|
Final Update:
Microsoft, you've won. I've been beaten into submission. Despite countless forum posts, weeks of web research, and direct queries to MS employees with no solid answer, I've succumbed to the workaround.
Here's what to do:
1) Follow my original instructions to use the nullabledatetimepicker. modify it to accept 1/1/1900 as it's "null" value, so it shows the null string but reports it's value as 1/1/1900.
2) change your DB schema so that all dates are NOT nullable. Set the default value to 1/1/1900 12:00:00 AM, or getdate(), depending on what you're doing with it. You'll also need to do an update query for all NULL dates to set to '1/1/1900 12:00:00 AM'.
3) match the DS to the DB schema.
4) adjust any code in your program to understand the 1/1/1900 value as actually "null".
5) Be over and done with it and get on with your life!
I hate workarounds. Maybe Visual Studio 2010 won't be such a compromised program...we shall see.
|
|
|
|
|
hi , iam pramod
i developing ERP project ,i want to do the custom installation of my application in vb.net windows application. That means when deploying my application, it should display different optiions like
typical installation,
full installation.
And after selecting any one of the option then , my application should deploy accordingly.
How to do such type of setup and deployment?
can anyone help plz.
please give me step by step process custom deploying.
modified on Friday, February 27, 2009 12:14 PM
|
|
|
|
|
You'll need an application that can create "installation-packages". One of those can be found here[^], Google knows more about them
I are troll
|
|
|
|
|
Just asking because this is a vague question. Have you looked at the Setup project in VS (Add new project, other project types, setup project).
This is a pretty basic setup package but good enough to get the job done. If you need more exotic options, you'll need to get something else.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Hi all
I did not make search or try it, but it is possible to
1- create vb.net project, add a function/class create in c# as is (not converting it to vb.net) ?
2- add 2 form, the first form is vb.Net and the second is vc++ or c# form?
TIA
Like car accidents, most hardware problems are due to driver error.
Samir R. Ibrahim
|
|
|
|
|
Samir Ibrahim wrote: I did not make search or try it
so maybe you should do that first?
"I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
You have various lang. projects in the same solution.
Solution Utils
printing.vbproj
display.csproj
etc.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
If the C# code is compiled into a library (DLL), you can use it. You cannot mix different languages in the same project source code though. For examples, you cannot have a VB.NET project (*.vb files), then include a class written in C# (*.cs). You can USE a DLL written in C# though. The same is true for C++.
You cannot mix languages inside the same project. But, you can have various projects, written in different languages, in the same solution..
|
|
|
|
|
Hi all,
this is Joseph,
I had designed one form in vb.net windows application.
It has one button.
when i click that button one e-mail should be sent to the specified customer ( gmail, yahoo , rediff, etc).
Can anyone give me the code to do this plz.
-joseph
vb.net
modified on Friday, February 27, 2009 8:23 AM
|
|
|
|
|
|
|
I have a part of my ini file
[temperature]
total=5
My code:
x=OSGetPrivateProfileString(" temperature","total","5",, sBuff, Len(sBuff), sIni)
byteTotal= Val(Left(sBuff, x))
Will the code give me byteTotal =5? What if there no those part( [temperature]) in my ini file? will it finally give me byteTotal =5?
Thanks
|
|
|
|
|
dec82 wrote: Will the code give me byteTotal =5?
Probably. What happened when you executed the code? No errors?
dec82 wrote: What if there no those part( [temperature]) in my ini file?
GetPrivateProfileString asks for a default value. It will return this value if the section or the named value doesn't exist
I are troll
|
|
|
|
|
hi all
i have bind a listbox to dataset with mulitpleselection property of listbox.
on a button click i want to reterive all the selected value by user.
please help
if possible paste the code
thanks
jagwinder
Er. Jagwinder Singh
|
|
|
|
|
Nonu Walia wrote: if possible paste the code
I refuse to paste any code by moral conviction
Take a look at the property called "SelectedItems". That's a collection of all the items that are selected by the user, being a subset of all available items.
You can use a foreach to loop through them.
I are troll
modified on Friday, February 27, 2009 5:02 AM
|
|
|
|
|
i did like this
For each Item in listbox1.selecteditems
next
cud u tell me what will the Item data type???
and how i will get the selectedvalue??
Er. Jagwinder Singh
|
|
|
|
|
Dim idx as Integer
For Each idx in myListBox.SelectedIndices
' Do something interesting here
Next
I are troll
|
|
|
|
|
Hi Guys,
I need to convert rows to columns,
I have a table shown below
ColA....ColB
X XX
X YY
X ZZ
do you know how to query this table to get a result set like
this below
ColA...ColB...ColC...ColD
X XX YY ZZ
I have tried to use a pivot query but fail to get the desired output,
please help,
thanks in advance
Anoop
|
|
|
|
|
Hi all,
I'am developing a desktop application using vb.net. I've a form with infragistics ultragrid control which populates data from database and three graphs using mschart controls. I want to have a print preview and take a print of the form (including data table and 3 graphs). can anybody provide me with sample code for print preview and print.
Thanks in advance
|
|
|
|
|
here's some code I did for print and print preview using ultragrid(grdgridmaster is the name of my grid).
You will have to code individually for each grid you want to print.
Also drag the UltraPrintPreviewDialog object onto the form.
Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
Dim printdocument1 As New System.Drawing.Printing.PrintDocument
Dim printdialogue1 As New System.Windows.Forms.PrintDialog
Try
printdialogue1.Document = printdocument1
If printdialogue1.ShowDialog() = Windows.Forms.DialogResult.OK Then
grdGridMaster.Print(grdGridMaster.DisplayLayout, printdocument1)
End If
Catch ex As Exception
MessageBox.Show("An error occurred - " + ex.Message)
End Try
End Sub
Private Sub PrintPreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewToolStripMenuItem.Click
Dim UltraGridPrintDocument1 As New Infragistics.Win.UltraWinGrid.UltraGridPrintDocument
UltraPrintPreviewDialog1.Document = UltraGridPrintDocument1
UltraGridPrintDocument1.Grid = grdGridMaster
'maximize the window
Me.UltraPrintPreviewDialog1.WindowState = FormWindowState.Maximized
UltraPrintPreviewDialog1.ShowDialog()
End Sub
|
|
|
|
|
Hi,
I am new to this vb.net, my problem is i have build the windows service in vb.net c#. I deployed it in my system when i am trying to start that service it showing the error as
Error:1053 could not start the service on Local system
The service didnot respond to the start ro control request in a timely fashion
I cleared Applicaton event log also. I checked in system log. It shows the message as follows
1.Information: The Windows Installer service was successfully sent a start control.
2.Information: The Windows Installer service entered the running state.
3.Information: The Windows Installer service entered the stopped state.
4.Error: Timeout (30000 milliseconds) waiting for the windows service to connect.
5.Error: The Samplepolaris service failed to start due to the following error:
The service did not respond to the start or control request in a timely fashion.
I have tried to resolve it, but i could not... Please help me to solve this problem.
Thanks in advance.
With Regards,
Samson
|
|
|
|
|
Always tough to educated guess without seeing some of the startup code but this could be a permission issue. Perhaps your service logon does not have the necessary privileges on the service computer? If you haven't tried debugging the service yet it is really not difficult and I am sure you can google for info on how to debug a windows service.
|
|
|
|
|
From the description, it sounds like you put all of your work code into the OnStart method, never letting it return. This is why the Service Controller threw up the timeout error.
When a service starts, it's expected to setup a seperate thread that does the actual work. Once the thread is setup and started, your OnStart code can return control back to the Service Controller by just getting to the End Sub statement.
|
|
|
|
|