|
Your question doesn't make much sense and you're leaving out some critical details. DbNull is a value where DateTime is a data type. You cannot change one for other.
How was your DataSet/DataTable created?? You cannot change just a column in one row in a table to have a different datatype from the rest of the rows in the table. It's all or nothing.
|
|
|
|
|
I am reading data from an excel spreadsheet, some fields are text and others are dates. I then read each line into a datarow in a dataset and then pass them to a method to insert them into an access table. Her is my read from excel code:
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [sheet1$]", MyConnection)
MyCommand.Fill(DtSet, "ExcelFields")
MyConnection.Close()
Dim ir As New DBTier
Dim va As New Validate
Dim dr As DataRow
For Each dr In DtSet.Tables("ExcelFields").Rows()
va.ValidateFeilds(dr)
ir.IncidentReportAdd(dr.ItemArray(0).ToString(), dr.ItemArray(1).ToString(), _
dr.ItemArray(5).ToString(), dr.ItemArray(7).ToString(), dr.ItemArray(2).ToString(), _
dr.ItemArray(8).ToString(), dr.ItemArray(10).ToString(), dr.ItemArray(12).ToString(), _
Date.Parse(dr.ItemArray(13).ToString()), Date.Parse(dr.ItemArray(14).ToString()), _
Date.Parse(dr.ItemArray(15).ToString()), Date.Parse(dr.ItemArray(16).ToString()), _
Date.Parse(dr.ItemArray(18).ToString()), Date.Parse(dr.ItemArray(19).ToString()), _
dr.ItemArray(21).ToString())
Next
I need to be able to check if the date is blank and replace it with 1/1/1900 if it is.
|
|
|
|
|
forgot to say, validate is where i'd like to change the fields value if it's empty.
|
|
|
|
|
OK, so this ValidateFields method is going to have to iterate through each column in the DataRow and check to see if each field is valid. Since a DateTime field cannot be Nothing (null), you can put in any date you want instead.
|
|
|
|
|
I have purchased Samsung Receipt printer and a cash drawer. I can print to printer. but I cannot open a cash drawer after printing invoice. the provider gave me a command code for Epson printer is "PRINT #1, CHR$(&H1B);"p";CHR$(0);CHR$(100);CHR$(250);". But I don't know how to use this code in VB. can u pls help me to solve this probs.
THank u...
|
|
|
|
|
harisqued wrote: "PRINT #1, CHR$(&H1B);"p";CHR$(0);CHR$(100);CHR$(250);". But I don't know how to use this code in VB.
All this does is send a few control characters to a port opened as file stream #1. That port may be COM1, COM2, LPT1, ... and you open then just as you would any other file in VB6, using an OPEN statement.
|
|
|
|
|
Hi.
I have little experience with VB & VB .NET. I have to work on an existing project and I found these lines in it:
Dim [unicode] As System.Text.Encoding = System.Text.Encoding.Default<br />
<br />
' Convert the string into a byte array.<br />
Dim unicodeBytes As Byte() = [unicode].GetBytes(val)
I don't understand... what kind of declaration is that? (Dim [unicode]...)
Any idea?
Thanks.
|
|
|
|
|
I've never seen that before either, but VB.NET obviously allows it, or your code wouldn't compile. I doubt it means anything special beyond that VB has a history of letting users do weird and crappy things.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
The square brackets tells the compiler it is a variable rather than a reserved word.
For example, I should not be able to use the following declaration :-
Dim Next As Object
or
Dim Form As System.Windows.Forms.Form
as Next is a reserved word and Form is a Class, but I can do the following declaration
Dim [Next] As Object
or
Dim [Form] As System.Windows.Forms.Form
Steve Jowett
-------------------------
It is offen dangerous to try and see someone else's point of view, without proper training. Douglas Adams (Mostly Harmless)
|
|
|
|
|
Thanks. It seems that the usefulness of the construct is lesser that the confusion it induces. I wonder if C# has anything similar.
|
|
|
|
|
Hi,
the C# compiler does not accept int for=1; but it does accept int @for=1; i.e. identifiers
can start with an @ so keywords become acceptable as regular identifiers.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
The [] around the variable names allow you to have a variable name the same as a keyword, much the same as in SQL you can have tables and fields with names the same as sql keywords.
This is most useful in Enums:
Private Enum Result
[Error]
Failure
Ok
End Enum
Error is a VB.net keyword, but "Result.Error" isnt.
In this instance, I can only assume Unicode is a type imported, so it has been enclosed in square brackets to make the compiler happy.
|
|
|
|
|
Imiss in this code detect path of servivce
Sub ReadSvcs() 'of his old football
Dim ListSvcs() As ServiceProcess.ServiceController 'games from back in the day,
Dim SingleSvc As ServiceProcess.ServiceController 'when "your mother and I were dating." But the
Dim LVW As ListViewItem 'warm fuzzy of nostalgia,
ListSvcs = ServiceProcess.ServiceController.GetServices 'knowing that yes, you accomplished something, makes the world
'ListSvcs = SingleSvc.GetServices 'knowing that yes, you accomplished something, makes the world
lvwServices.Items.Clear() 'feel a bit easier to deal with, and
Try 'eventual death acceptable, almost as though we
For Each SingleSvc In ListSvcs 'have made
LVW = lvwServices.Items.Add(SingleSvc.DisplayName) 'indelible marks upon the history of whatever.
LVW.SubItems.Add(SingleSvc.ServiceName) 'But a sigh usually caps off the standard c**k-
LVW.SubItems.Add(SingleSvc.Status.ToString) 'stroking session of the BBS-days bullshit, when we had
LVW.SubItems.Add(SingleSvc.ServiceType.ToString) 'only 32 baud modems. Maybe it's that I need to know
'LVW.SubItems.Add(SingleSvc.Site.Name)
Next 'how little I knew, how young I was, to re-
Catch e As Exception 'assure myself of the growth that I have (?) experienced,
MessageBox.Show("Could not initialize Windows Service engine. Restarting your computer may work", "Fatal Error: " & e.Source)
End Try 'magic marker lines with my handle and the date, maybe
End Sub 'a dial-i
Ahmed hassan
|
|
|
|
|
What is this crap ? What's with the weird comments ? Do you have a question ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I see 3 questions now, unfortunately I don't know the answers to them.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Yeah I eventually worked out that he had no idea how to edit his posts.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello
I am making small quiz with vb.net 2003 and all the questions and options are in access database there is one column for question and 4 columns for wrong answers and one for correct answer
this is the code
Try<br />
Do<br />
odaTest.Fill(dsTest)<br />
R = CInt(Int(ArraySize * Rnd()))<br />
<br />
'[Go to the next entry]<br />
Me.BindingContext(dsTest, "MyTest").Position = R<br />
Loop Until Asked(R) = False<br />
PoAns = DataView1.Item(R).Item("CorrectAns")<br />
WAnswer(0) = DataView1.Item(R).Item("Op1")<br />
WAnswer(1) = DataView1.Item(R).Item("Op2")<br />
WAnswer(2) = DataView1.Item(R).Item("Op3")<br />
WAnswer(3) = DataView1.Item(R).Item("Op4")<br />
'randomize 4 options<br />
For X As Integer = 0 To 3<br />
MyTB(CInt(Rnd() * 3)).Text = WAnswer(X)<br />
<br />
Next X<br />
<br />
'now randomize one correct answer<br />
MyTB(CInt(Rnd() * 3)).Text = PoAns<br />
AskedQ += 1<br />
Asked(R) = True<br />
Catch eLoad As System.Exception<br />
MessageBox.Show(eLoad.Message)<br />
End Try
And i am checking correct answer like this
Private Sub CheckAnswer()<br />
If CheckedTB.Text = PoAns Then<br />
MsgBox("Right", MsgBoxStyle.MsgBoxSetForeground)<br />
End If<br />
<br />
End Sub
So now problem is some time it's shows same wrong answer in two different textboxes but it's shows correct answer in different textbox every time so now i am bit confuse that am i going in to right direction any help
|
|
|
|
|
You need to put your questions in a list and pull from them randomly, removing them as you pull. Right now, you are pulling randomly from the full list every time and so will have duplicates.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello sir
First of thank you very much for your rep.
But sir problem is not questions it's working fine and it's not repeating at all because i have set one Boolen variable so it's True that question which has been asked but problem is options for any question like i have 4 columns for wrong answer and one for correct answer so i am randomizing it first and then i am randomizing the one correct answer to display in text box so main problem is some time it's displays same options in two different text boxes and i am sure i am very close to it but some time it's hard to see small errors and code bellow is to randomize 4 options and one correct answer
'randomize 4 options
For X As Integer = 0 To 3<br />
MyTB(CInt(Rnd() * 3)).Text = WAnswer(X)<br />
<br />
Next X<br />
<br />
'now randomize one correct answer<br />
MyTB(CInt(Rnd() * 3)).Text = PoAns
and second thing sir the way i am checking correct answer is it the right way to check it or some thing else ?
code is like this
the first line gets the correct answer for asked question and put it in to PoAns variable
PoAns = DataView1.Item(R).Item("CorrectAns")
Private Sub CheckAnswer()<br />
If CheckedTB.Text = PoAns Then<br />
MsgBox("Right", MsgBoxStyle.MsgBoxSetForeground)<br />
End If<br />
<br />
End Sub<br />
Private Sub txtA_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtA.Click, txtB.Click, _<br />
txtC.Click, txtD.Click<br />
CheckedTB = CType(sender, TextBox)<br />
Call CheckAnswer()<br />
<br />
End Sub
waiting for your kind rep.
thanks again for your rep.
have a nice day sir
|
|
|
|
|
OK, you have it in reverse. You're not actually going to select all four textboxes, because you are doing what I already told you is wrong - four random numbers instead of 0,1,2,3 sorted randomly.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
hello sir
yes i got it and i have done it as you said this is my stupid mistake sir
and this is the code and it's works fine all along i was thinking that i am randomizing wrong answers but i wasn't i was randomizing textbox which is not possible but any way this the way i learn
thanks again
Dim X, Y As Integer, Placed(3) As Boolean<br />
For X = 0 To 3<br />
Do<br />
Y = CInt(Int(Rnd() * 4)) ' Randomize 4 wrong answers<br />
Loop Until Placed(Y) = False 'Loop until it's not same number<br />
Placed(Y) = True<br />
MyTB(X).Text = WAnswer(Y) ' Place randomly selected wrong answer in text box <br />
Next<br />
<br />
'now randomize one correct answer<br />
MyTB(CInt(Rnd() * 3)).Text = PoAns
thank you very much sir
have a nice day
|
|
|
|
|
I'm doing this form that has a glossary. I created the alphabitical letters using link labels, and the glossary using labels. How can write the code so that when a click on one of the letters(link labels) i go to the grossponding letter( label )
Regards,
Senior MeMe ..
|
|
|
|
|
Handle the click event and call the focus method on the label you want to focus on.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
i stil can't solve my problem in database i have use sql to store my date
INSERT INTO `LOGIN/OUT` (`Time_login`, `Time_logout`)
VALUES (?, ?, ?, ?)
but i stil can't save anything..the method i use was drag and drop
when writing code i use tableadapter to save ir it it's gave me error
LOGIN_OUTBindingSource.EndEdit()<br />
LOGIN_OUTTableAdapter.InsertQueryEmp(Me.Definition_dbDataSet )
can anyone here help me solve it..actually how to insert time into database.data type i use date/time.
|
|
|
|
|
SQL statements are weird in .NET. You have to request insert commands from the adapter and it becomes a hassle. Here is a working example of what you need to do to create a new row in SQL:
<br />
Dim strTopic As String = InputBox("Enter a topic")<br />
Dim sql As String = "SELECT ID, CourseID, Topic FROM tblTopics WHERE ID = 0"<br />
Dim da As New OleDbDataAdapter(sql, cn)<br />
Dim ds As New DataSet<br />
da.Fill(ds)<br />
Dim cmdbuilder As New OleDbCommandBuilder(da)<br />
da.InsertCommand = cmdbuilder.GetInsertCommand<br />
Dim dr As DataRow = ds.Tables(0).NewRow<br />
dr("CourseID") = Me.lngCourseID(Me.cboCourse.SelectedIndex)<br />
dr("Topic") = strTopic<br />
ds.Tables(0).Rows.Add(dr)<br />
da.Update(ds)<br />
cn.Close()<br />
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|