|
I have a data type is smalldatetime in the sql table, when I bind to my DataTable in VB.NET, when there is value in this column, the output is fine, but when it's NULL, then it gets error of the data type. In the sql, if it's string, I do ISULL(firstname, '') AS firstName inside sql query, then the output is fine, but I don't know how to convert the null smalldatetime. Is there any idea?
Lisa
|
|
|
|
|
|
I'm doing the OleDbDataReader in the vb appl.
THis is my code:
Dim OrderDate as date
Dim DataAdapter As New OleDbDataAdapter
Dim DataReader As OleDbDataReader
**connecting***
**sql query**
Select dateOrder from orderTable
***
DataReader = DataAdapter.SelectCommand.ExecuteReader()
Do While DataReader.Read()
OrderDate = DataReader.GetDateTime(0)
Loop
lblOrderDate.text = OrderDate
Where should I check the value of the column before using it?
If the dateOrder is Null, then this OrderDate = DataReader.GetDateTime(0) will get error.
THanks
Lisa
|
|
|
|
|
Okay - You are using a SqlDataReader, I assumed you had a dataset. By the way, if you are extracting data through a data reader then using a data adapter is redundant. Just build the SqlCommand object and use that.
Anyway, I've modified your code:
DataReader = DataAdapter.SelectCommand.ExecuteReader()
Do While DataReader.Read()
If Not DataReader.IsDBNull(0) Then
OrderDate = DataReader.GetDateTime(0)
Else
' Do something else because the data time is null
End If
Loop
Does this help?
Disclaimer - I typed this directly. There may be typos, syntax errors, etc.
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
Thanks! it works much better..
but there is one more thing.
how can I covert a Date type to a String type in vb?
The OrderDate is Date type, and I want it to be OrderDate= "" when it's NULL.
Lisa
|
|
|
|
|
|
it won't work when I do this...
Dim OrderDate as String
inside DataRead
If Not DR.IsDBNull(0) Then
orderDate = DR.GetDateTime(0).ToString("MM/dd/yyyy")
Else
orderDate = "" ***here is not working***
End If
any idea?
Lisa
|
|
|
|
|
Try
orderDate = IIf(IsDBNull(DR.GetDateTime(0)),"",DR.GetDateTime(0))
IIF(expression,Truepart,falsePart)
|
|
|
|
|
I tried your code, but the output is like this:
when the GetDateTime(0) has value, then it output empty, run time is fine, but if GetDateTime(0) is Null, then it has error "Specified cast is not valid"
do you know why?
thanks.
Lisa
|
|
|
|
|
I noticed that you are trying to put the datetime into a string variable.
Since your variable is not a date do not use GetDateTime.
orderDate = IIf(IsDBNull(Convert.ToString(DR(0))),"",Convert.ToString(DR(0)))
DR(0) should match the column or use the Column Name DR("COL_NAME")
Or try to use a non Date datatype
orderDate = IIf(IsDBNull(Convert.ToString(DR.GetValue(0))),"",Convert.ToString(DR.GetValue(0)))
play around with this.
|
|
|
|
|
Hi,
Just wondering if anyone knows of an easy way to create a wizard in vb.net ! I will be using it to lead the user through a series of questions and store their responses.
I am using Visual Studio Profesional 2003
Any help would be FAB !!!
Thanks
Martin
|
|
|
|
|
oops forgot to say that the wizard will need to be part of a web app.
|
|
|
|
|
Each page is going to ask a question or two. When the user clicks Submit, it calls back to the server where those values are stored (probably in a database associated with a session ID), then baced on those values, the page will have to chose the next page to redirect to. Where the same thing happens again... Until all your questions are answered.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
HI,
Yep that is exactly what i need . but i am still not sure of the best way to make it
Any help would be FAB !!
Thanks
Martin
|
|
|
|
|
I would like to know the code for adjusting the length of scrollbar if i want to shorten the length of the scrollbar and add a picture below the scrollbar. Currently i'm using AutoScroll function.
|
|
|
|
|
You don't. The scrollbar automatically adjusts itself depending on the length of the client area it controls.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I want to know how you can take global variables as strings in VB and write them into an existing pdf in the correct areas.
|
|
|
|
|
1. Global variables are a good sign that whoever wrote your code has no idea how to program
2. The location of variables has nothing to do with the ability to put them into a PDF
3. Unless you have created the PDF yourself, and it's not compressed, you'll need a third party tool to do this.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I've created the pdf myself. What I want to do is put the variables into fields in the pdf. How do I do this?
|
|
|
|
|
SAve the PDF without compresion. Any field you want to be able to set, fill it with a unique string, and spaces to fill it to the maximum length you'd want. Then load the file, look for the strings and replace them.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
hi, i need help on vb6
how can i chang the standard form to obtain
and other shape.
for example, i want to locate my command buutons
on circle shape not on standard form.
|
|
|
|
|
You need to make 2 API calls:
CreateRoundRectRgn - API to create a rounded rectangle region.
SetWindowRgn - API called with the form handle to set the form's region to the rounded rectangle created with CreateRoundRectRgn.
Search the MSDN for these two APIs to learn how to use them.
Robert
|
|
|
|
|
Hi,
I want to check whether the email ID entered in the text field is proper or not.
What can I do?
|
|
|
|
|
|
Help!
This begins my third week of teaching myself VB6, and graphics are hurting my brain.
I've been trying to load and do things that should be simple with images, like scaling them or changing their format then displaying the changed image, with image quality in mind. Examples of this are very few, and I don't really understand what I'm looking at in the code, anyway.
I downloaded FreeImage from SourceForge, but even that is proving to be a pain. I just can't get images to display in picture boxes.
Does anyone know of any good VB6 tutorial websites that have clear examples of this sort of thing?
My ambition is to make my own thumbnailer and maybe image editor so that I can learn how graphics work in VB6.
Thanks much!
I am the very model of a modern newbie programmer,
Crashing my computer 'cause my code creates a clamor.
My code and little programs are all never quite original,
I even stole this piece of music from a major general.
|
|
|
|