Assign Null Value To Date/time Variable?

Jun 7, 2011

Attempting to convert a possible null value into date/time field. Any easy way ?

[Code]...

View 5 Replies


ADVERTISEMENT

Assign DBNull.Value To A Variable, Or Write NULL To MSSQL Database?

Dec 3, 2009

I have a little problem regarding the use of DBNull, NULL etc. in VB.net in combination with SQL Server 2k.

More specifically, I want to do something along the lines of this:If x = 0 Then

x = DBNull.Value where x is declared by Dim x as Object. I would rather use Double, but I can't assign DBNull.Value to this, and using Object works quite well, too. But every time I hit this condition, I get an exception: A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll This is not a major show-stopper, since the database value I write x to in the next step, is NULL by default - most of the time! So I need the ability to write NULL to it. If that was not the case, I would have been able to work around this by catching exceptions, I think - but sadly, this isn't really of use then.

View 4 Replies

VS 2008 - Assign Value To Date Variable And Compare It With Another

Jul 30, 2009

Is this the correct way to get a datetime value using a sql datareader:
existingETA = existproformaReader.GetDateTime(0)
I want to assign the value to a date variable and compare it to another date variable.

View 8 Replies

Assign Value To Date Time Picker?

Feb 27, 2009

How can i assign value to a Date Time Picker object.

My scenario is this:

I have a dtp that handles timeIn and timeOut. I want that if my Restday check box is checked, my Timein and Timeout will be set to 0000.

Here's my

Private Sub chkRestDay_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkRestDay.CheckedChanged
If chkRestDay.Checked Then

[Code]....

View 11 Replies

Asp.net - Taking A NULL Value From The Database And Assigning To A Date Variable

Mar 11, 2009

A stored procedure returns data about a user record including a nullable datetime column for their last login date. Which one is the better choice in dealing with the possibility for NULL values when trying to assign a .Net date variable?

Try
_LastLogin = CDate(DT.Rows(0)("LastLogin"))
Catch ex As InvalidCastException

[Code]....

Which is the preferred method of handling possible NULL values from the database? Is there a better way than the three listed?

Edit #2: I have noticed that the TryParse method does not play nice when trying to assign to a Nullable type.

View 5 Replies

How To Add Both Date And Time In DateTime Variable

Feb 1, 2012

I have two datetime variables in VB.Net [code]I want to add both these variable in single DateTime variable , i didn't find any .Net function to do that.Is there any other way to do it?

View 2 Replies

VS 2008 Add A Date To A Time Variable?

May 30, 2011

I have a Date variable called Time1In.

I'm getting a time value as a string from Excel, so I assign the date variable a value like this:

the string value coming in from excel is this:

30/12/1899 7:40:00 AM

my code gets the time value and assigns it to the date variable:

TimeIn1 = TimeValue(strTimeIn1)

the Date variables value is then this:

#7:40:00 AM#

which inserted into my database datetime field then looks like this:

0001-01-01 7:40:00

That causes errors when loading the page. I need to set a date value on the date variable. How can I properly append a date to the variable?

View 6 Replies

Saving A Date Time Picker Value To A Variable?

Jul 6, 2010

I have the following Public Class Payroll Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged

[Code]...

and I'm trying to save the datetimepicker value as a variable to pass to a sql database. I'm just not sure what the datetimepicker value is, is it Me.DateTimePicker1.Value or is it dt?

View 3 Replies

VS 2008 - Append Now Time Part To Date Variable

Jan 11, 2010

I'm working on a small accounting app. I have a query to show transactions with a running balance.

SELECT transactionid, transactiondatetime,
amount,
(SELECT SUM(amount)
FROM dbo.transactions as D1
WHERE D1.transactiondatetime <= D0.transactiondatetime) AS balance
FROM dbo.transactions AS D0

I capture a gamesheet for a certain week. so if I select a date on a monthcalendar the sheet applies to the weeknumber of the selected date. When I save transactions I take the date at the last day of that week as the transactiondate. I need to store a datetime though because my query works of the datetime to get an accurate running balance. How can I append now() time part to my date variable and then store that in a datetime variable to get a transactiondatetime.

Here is my code for getting a transactiondate:
Dim dt As New Date
dt = Me.MonthCalendar1.SelectionStart
'get last date of week. Friday
Dim tdate As Date = dt.AddDays(5 - CInt(dt.DayOfWeek))

View 2 Replies

Date / Time Variable Stored In A Column In An SQLite Table

Jan 26, 2012

I have a date/time variable stored in a column in an SQLite table. I need to select the string with the last 3 digits trimmed off. [code]

View 1 Replies

How Does DotNet Handle Parametrized Dates Where Programmatic Date Has No Time But Sql Date Has Time

Jul 16, 2010

Thought I'd see if Stack overflow is quicker than me testing something while I get a thousand interruptions from other work :)

I'm updating an old VB net application and trying to refactor some of the logic as I go. The app looks for data from a single date across a few tables and writes that view to a file.

Writing the query in SQL I'd get the equivalent of

SELECT * FROM table
WHERE CAST(FLOOR(CAST(table.date AS float))AS datetime) = '15-Jul-2010'

Ideally I'd use

SELECT * FROM table WHERE date=@input

and add a date object as a parameter to a System.Data.SqlClient.SqlCommand instance

Are those two comparable? Will I get the results I expect?

View 1 Replies

Record A Start Date And Time And Then The Stop Date And Time In A Rich Text Box

Jan 12, 2010

I am using VB 2008 and want to record a start date and time and then the stop date and time in a rich text box, i can get the start time into the box but so far can only stop the time instead of 2 seperate times, what i have is a drop down box with a list of computers 1-10 i was trying to get it so you picked a certain computer and that went into the text box then you started the timer and that was recorded, finally you stopped the timer and that was recorded but as i am a total newbie it does not work

Here is the code i have.

Public Class Form1
Dim time2 As Date

[CODE]...................

View 11 Replies

Asp.net 1.1 - Assign Null Value To Optional Parameters In .NET 1.1?

Dec 21, 2010

I tried DbNull.Value but no luck. How do I assign a default value as null to a string parameter that is null in VB.NET? Its litte strange to see that VB does not have anything like plain null as most of the other languages do. Also what is the difference between null and DbNull and Nothing.

View 3 Replies

How To Assign The AppDate To NUll Like DBNull

Mar 5, 2010

I am not sure why VB makes everything such a pain. I have a fields which stores the date and time in the format required to store in MySQL database

[Code]...

Now I need to assign the AppDate to NUll like DBNull, but I am not able to do it directly. If I change AppDate to Date then I am not getting the required format.

View 5 Replies

Assign A Value To Nullable Integer Via A Ternary Operator / It Can't Become Null

Apr 19, 2012

If you assign a value to a nullable integer via a ternary operator, it can't become null..While this question may seem like a duplicate of many, it is actually being asked for a specific reason.Take this code, for example: Dim n As Integer? = If(True, Nothing, 1) In that code, the ternary expression should be returning Nothing, but it's setting n to 0. If this were C#, I could say default(int?) and it would work perfectly. Now it looks like I am going to have to ditch the ternary and use a regular If block, but I really want to use the ternary. If Nothing were truly VB.NET's equivalent to C#'s default, how can you explain this behavior?

View 1 Replies

Assign Data To An Array From A Text Box - Null Reference?

Apr 24, 2011

when i try to assign data to an array from a text box, i get a null reference exception, stating "Object reference not set to an instance of an object".

View 5 Replies

SQL Exception On Insert Of Dateandtimepicker.value.date Into Date Datatype: (Conversion Failed When Converting Date And/or Time From Character String)

Apr 8, 2010

Title pretty much says it all. How do I format the date of a dateandtimepicker to insert it into the SQL date datatype?

View 20 Replies

Combo Box Selected Item Is Null - Assign An Empty String To It Instead?

Dec 9, 2011

I have a property called ReplacementTo and I set a value to it based on the selecteditem from the combobox, like this:

classEquipmentItem.ReplacementTo = cmbReplcmnt.SelectedItem.ToString

Now I can't use cmbReplcmnt.Text because what I actually need is the value of that SelectedItem

So problem is, if the user leaves the combobox as blank, it throws a null exception.I decided to use the IIf function then:classEquipmentItem.ReplacementTo = IIf(IsNothing(cmbReplcmnt.SelectedItem.ToString), classEquipmentItem.ReplacementTo = "", cmbReplcmnt.SelectedItem.ToString)

Unfortunately I still get the error I tried using a Try-Catch for it and it worked, but I don't want to rely on the Try-Catch, so I was wondering is there a another way to work this through?

View 2 Replies

C# - Convert A Date And Time To UTC Time Based On The Time Zone Of The User?

Sep 6, 2009

I have an ASP.NET application with a SQL Server back end. I am storing all my dates in UTC format and doing the appropriate conversions to the local time zone of the browser viewing it. One of the pages asks for a start date and end date (no times).

I am taking the start date and setting the time to 00:00:00 hours (midnight) and I'm taking the End time and adding a time of 23:59:59, so that the date range covers the whole day. Now what I'm trying to do is do a SQL query to do a search for records in this date range. The problem is, the data in SQL is in UTC time and the user is typing their dates and times in their local date and times. My quickest solution was to convert the date and time to UTC, then search the records. However, by doing this, I am to believe ASP.NET converts the given time and date to UTC based on the server time zone. How can I convert a date and time to UTC time based on the time zone of the user?

View 5 Replies

Assign Each Value To Its Own Variable?

Apr 27, 2011

I have a file txt file that holds 3 values each seperated by a space how can i assign each value to its own variable and use that for other things?

View 4 Replies

Assign A Resource According To A Variable?

Apr 2, 2010

I've been making this BlackJack program for a school project

I have 52 image files, labelled from '_1' to '_52' in my resources folder, each number corresponds to a card.

My question is, how do I get a picture box to assign the correct resource according to a variable

So, say I have

"pictDealerCard1" -> picture box which displays the first of the dealers card
DealerCard1 = 37 -> random number generated through INT(RND() * 52)
and resource '_37'

[Code].....

View 3 Replies

Assign A Variable In A While Statement?

Oct 12, 2009

I need to assign a varible in a while clause. I.e., i would do it in php like this: while (!is_bool($char=$this->getChar()) in every loop, the function would assign $char a value, the is_bool function would test it, and the code INSIDE the while clause would have access to that $char.

View 4 Replies

Assign The Value Of A Combobox To A Variable?

Jul 18, 2012

i would like to assign the value of a combobox to a variable and use this variable as a parameter on the insert statement.see code below,code 1 works ok,but code 2 brings an error relating to wrong datatype,i cant seem to find where the problem because i think i am doing everything right.

[Code]......

i would like code 2 to work so that i can assign the variables different values at different scenarios. column serialno is a foreign key from table Stock.

View 9 Replies

Assign Value To A Variable In Lostfocus?

Mar 9, 2012

I want to assign a string value to a variable in the DataGridView LostFocus event. I found that I can't just do variable = "string value, it will give me the "Unable to cast object of type 'system.eventargs' to type 'system.windows.forms.datagridviewcelleventargs'" error.

The function created by double-clicking on the datagridview is:

Private Sub DataGridViewInvoice_LostFocus(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridViewInvoice.LostFocus

View 1 Replies

DataSource - How To Assign Value To Variable

Jan 22, 2009

I'm trying to retrieve data from an access database, but I'm trying to do it all in VB. Basically I need to query the database, and I think I've done that correctly. But then I need to assign the value in a certain field, to a variable. So for example,
Dim email = orders.CustomerEmail.
How to assign a value to a variable.

Below is my current code:
Dim acc
As
New AccessDataSource()
accDS.SelectCommand = "SELECT TOP 1 orders.OrderDate, orders.OrderNumber, orders.OrderProduct, orders.OrderTotal, orders.CustomerName, orders.CustomerPostCode, orders.CustomerEmail"
accDS.DataFile = "~/App_Data/Database.mdb"

View 3 Replies

How To Assign A Setting Value To A Variable

Jan 23, 2010

I get nothing but headaches when I try to update settings in the My.Settings class, or when I try to assign a newly assigned setting to a variable. Sometimes the settings update OK at run time; other times times they update only after the application closes; and other times still they appear to update at run-time, then when I close the program and reopen- they go back to the previous settings.This is how I assign a value to a my settings and how I assign a setting value to a variable.[code]

View 6 Replies

How To Assign Field Value To Variable

May 11, 2010

I'm new with vb.net my problem is how to assign field value from database to a variable here is my code

Call connectdatabase()
dim uname as string
dim pass as string
Try
sql = "SELECT * FROM user;"
command.Connection = conn
[Code] .....

View 1 Replies

String Variable To Assign A Value?

Jun 18, 2012

i like to assign html codes to String variable

Dim code As String
code= " <meta http-equiv="Content-Type" content="text/html; charset=windows-1254"> "

i think i am getting this error because of double Quotation marks "character constant must contain exactly one character."how can i assign it to a string?

View 4 Replies

Assign Combobox.selectedvalue To A Variable?

Jul 31, 2009

I would like to assign cboBegCust.SelectedValue to c and cboEndCust.SelectedValue to d

Dim c, d As String
cboBegCust.SelectedValue = "customer"
cboEndCust.SelectedValue = "customer"

[Code]....

View 2 Replies

Assign The Value To Multiple Variable Of Same Type In .net?

Nov 22, 2006

I want to Assign the Value to Multiple Variable of same type in .net and that to in one line of Code.

View 6 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved