|
Datagridview1.CurrentCell = Datagridview1('Your column index', Datagridview1.NewRowIndex)
Datagridview1.BeginEdit(True)
|
|
|
|
|
Dim cn As New OleDbConnection
Dim adapter As New OleDbDataAdapter
Dim dtset As New DataSet
Dim dt As New DataTable
Dim cmd As New OleDbCommand
Dim sqlconnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sourceDirectory & ";" & _
"Extended Properties=""Text;HDR=No;"""
cn.ConnectionString = sqlconnectionString
'Open the Jet connection to read the CSV file
Try
cn.Open()
Catch e As Exception
End Try
Try
'Connection to the csv file and dump the data into a dataset
cmd.Connection = cn
cmd.CommandText = "Select * from " & sourceFile
'Attempt to fill a Datatable with the data from the CSV
adapter.SelectCommand = cmd
adapter.Fill(dtset, "CSVdata")
dt = dtset.Tables("CSVdata")
cn.Close
I am trying to read a csv file without any headers but I am getting one record short of actual no of rows. Is there something I am missing. The HDR option isn't really helpful.
Thanks in advance
|
|
|
|
|
I want to be able to determine the drive letter of an external USB device. If I use DriveInfo, the device is rarely, if ever, detected. If I use Scripting.Drive it sees the external device each time. Why is this?
Code that does NOT work:
Dim allDrives() As DriveInfo = DriveInfo.GetDrives()
Dim uutDrive As String
Dim drive As DriveInfo
For Each drive In allDrives
If drive.IsReady = True Then
If drive.VolumeLabel = WaffleVolumeLabel Then
uutDrive = drive.Name
Exit For
End If
End If
Next
Code that WORKS:
Dim fso As New Scripting.FileSystemObject
Dim drv As Scripting.Drive
Dim string_builder As New System.Text.StringBuilder
For Each drv In fso.Drives
If drv.IsReady Then
If drv.VolumeName = WaffleVolumeLabel Then
uutDrive = drv.DriveLetter & ":\"
End If
End If
Next
|
|
|
|
|
Hi,
There is quite a difference between "rarely" and "if ever" and without a crystal ball I'm not sure what "does not work" actually means.
It would be helpful to step through your code with the debugger to locate the point of failure.
I would initally find out if :
1) The code is being called at all
2) The allDrives array contain an entry for the USB drive
If allDrives is OK then step forward into the loop and figure out why your volume label is not being detected.
Is string comparison in VB.Net via the = operator case sensitive?
Alan.
|
|
|
|
|
Thanks for the response Alan!
What I mean by rarely is the any information on the attached external usb device is detected about 5% of the time that I run the code with the allDrives whereas as with the scripting.drives, the external usb device is detected each time. I am able to see all of other drives on my machine except the external USB device when stepping through the code. If I open file explorer, the external USB device is also shown. When I step through the code, most of the time no information on this device is seen (I've tried reading the drive name, the drive Format as well as the volume) and since none of this information is detected, I have concluded that for some reason, the allDrives isn't able to detect the device on a consistent basis.
So
(1) The code is being called as I can see other device
(2) The allDrives array does not contain entry for the desired device, but it does for another USB device (so an indication that the code can detect USB devices).
I do think the string comparison is case sensitive, but I have determined that this is not the problem as the block of code that works is able to make the match (and I also copied the volume name from file explorer to make sure the case would match).
|
|
|
|
|
Hi
I searched google for encryption algorithms to use
in vb 2008 and got one listed in CodeProject listed at
Making TripleDES Simple in Visual Basic .NET[^]
It encrypts the string fine but is not able to decrypt it
and shows the following message.
Length of the data to decrypt is invalid.
I searched google for the solution but not got any satisfying one.
what to do 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: what to do now?
fix the bug in your code. Make sure what the encryption generated is entered into the decryptor without any change. without any details, noone can help you.
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,
Can you please tell me what details you want?
My code is exactly as listed in the article shown above.
The string to encrypt is: encryptitman
The key I use is: 123456789012345678901234
The iv I use is : 12345678
The encryption goes on fine but the code is not able to decrypt the encrypted string.
I supply the encrypted string exactly to the decrypt function.
TheMrProgrammer
http://www.icbse.com/2009/funny-exam-answers-school-students
http://download.cnet.com/TheCalcMan/3000-2094_4-10958266.html
|
|
|
|
|
The article is followed by some discussions, where one of the participants is having the problems you're having, and he came up with a solution for it.
If it still would not work, you'd better post there.
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.
|
|
|
|
|
have created function in class file.
Public Shared Function dsCntrctET() As DataSet
Dim sqlCntrct As String = "Select * from CNTRCT_ET where CNTRCT_ID=" & CISCNO
Dim cmdCISContract As New OracleCommand
Dim daCISCntrct As New OracleDataAdapter
Dim dsCISCntrct As New DataSet
Dim cmdCISBuilder As New OracleCommandBuilder
Try
With cmdCISContract
.Transaction = myTransCIS
.CommandText = sqlCntrct
.Connection = cnCIS
End With
daCISCntrct = New OracleDataAdapter(cmdCISContract)
daCISCntrct.FillSchema(dsCISCntrct, SchemaType.Source)
cmdCISBuilder = New OracleCommandBuilder(daCISCntrct)
With daCISCntrct
.TableMappings.Add("Table", "CNTRCT_ET")
.Fill(dsCISCntrct)
.SelectCommand = cmdCISContract
.InsertCommand = cmdCISBuilder.GetInsertCommand
.UpdateCommand = cmdCISBuilder.GetUpdateCommand
.DeleteCommand = cmdCISBuilder.GetDeleteCommand
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return (dsCISCntrct)
End Function
it returns dataset that i can use for getting value from table.
but while saving data, i have to use dataadapter for da.update(ds,"table") and ds.acceptchanges.
this i have to use in multiple forms as this data comes from 3rd party so i dont want to write this in every form . so i thought how to return data adapter and dataset from the same function. as i wanted to use daCISCntrct and dsCISCntrct.
|
|
|
|
|
Pass any other objects you want to return in as an out parameter.
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 didnt really get you.
can you please provide some small example.
|
|
|
|
|
Hi Can someone please help, I am New to vb2005 Codeing so please be gentle.
Here is my code, I can only move forward or goto first but the .MovePrevious() and .Movelast()last give me an error.
Public Class Form1
Dim MyConnObj As New ADODB.Connection 'ADODB Connection Object
Dim myRecSet As New ADODB.Recordset 'Recordset Object
Dim sqlStr As String ' String variable to store sql command
Dim c As String
Dim tot As Long
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyConnObj.Open( _
"Provider = sqloledb;" & _
"Data Source=LINK-2927;" & _
"Initial Catalog=Sage200_DemoData;" & _
"User ID=sa;" & _
"Password=link12?;")
sqlStr = "select * from SLCustomerAccount"
myRecSet.Open(sqlStr, MyConnObj)
TextBox1.Text = "" & myRecSet.Fields!CustomerAccountName.Value
TextBox2.Text = "" & myRecSet.Fields!CustomerAccountNumber.Value
myRecSet.MoveFirst()
End Sub
Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextButton.Click
With myRecSet
.MoveNext()
If .EOF() = False Then
TextBox1.Text = "" & myRecSet.Fields!CustomerAccountName.Value
TextBox2.Text = "" & myRecSet.Fields!CustomerAccountNumber.Value
Else
.MoveFirst()
TextBox1.Text = "" & myRecSet.Fields!CustomerAccountName.Value
TextBox2.Text = "" & myRecSet.Fields!CustomerAccountNumber.Value
End If
End With
End Sub
Private Sub LastButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LastButton.Click
With myRecSet
.MoveLast()
If .EOF() = False Then
TextBox1.Text = "" & myRecSet.Fields!CustomerAccountName.Value
TextBox2.Text = "" & myRecSet.Fields!CustomerAccountNumber.Value
Else
.MoveLast()
TextBox1.Text = "" & myRecSet.Fields!CustomerAccountName.Value
TextBox2.Text = "" & myRecSet.Fields!CustomerAccountNumber.Value
End If
End With
End Sub
Private Sub previousButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles previousButton.Click
With myRecSet
.MovePrevious()
If .EOF() = False Then
TextBox1.Text = "" & myRecSet.Fields!CustomerAccountName.Value
TextBox2.Text = "" & myRecSet.Fields!CustomerAccountNumber.Value
Else
.MoveFirst()
TextBox1.Text = "" & myRecSet.Fields!CustomerAccountName.Value
TextBox2.Text = "" & myRecSet.Fields!CustomerAccountNumber.Value
End If
End With
End Sub
Private Sub FirstButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FirstButton.Click
With myRecSet
.MoveFirst()
If .BOF() = False Then
TextBox1.Text = "" & myRecSet.Fields!CustomerAccountName.Value
TextBox2.Text = "" & myRecSet.Fields!CustomerAccountNumber.Value
Else
.MoveFirst()
TextBox1.Text = "" & myRecSet.Fields!CustomerAccountName.Value
TextBox2.Text = "" & myRecSet.Fields!CustomerAccountNumber.Value
End If
End With
End Sub
End Class
Help
Thanks
Stephen
|
|
|
|
|
By the look of things, you are used to vb6. Welcome to vb.net.
Aside from the fact that you can do a lot of things much easier in vb.net / Visual Studio, the very first thing is error handling.
To find out what the error is, enclose the code in each sub in a try catch clause:
Private Sub FirstButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FirstButton.Click
Try
'your code here
Catch ex as Exception
MsgBox(ex.tostring)
End Try
End Sub
This will tell you what the error is, and exactly on which line it occurs (you can turn on line numbers in Visual Studio to make it easier).
My advice is free, and you may get what you paid for.
|
|
|
|
|
Thanks for the promt reply.
Stephen
|
|
|
|
|
Hi Experts,
I have a datagrid in which i want to give validation to each cell of my DataGridView...
such as 1st cell should take only "integer", 2nd "string"..........
Thanks
|
|
|
|
|
I use the CellValidating event of the grid and write my own validation methods. If the cell doesn't pass validation then you can call the CancelEdit() method which will revert the cell's invalid value back to the previous value.
|
|
|
|
|
Thanks for reply!!!
I am trying alot but got error for same.....can you please send me sample code for same....
|
|
|
|
|
If you post your code and the error you are getting I'm sure that myself or somebody else will be able to point you in the right direction.
|
|
|
|
|
Private Sub dgvstock_CellValidating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dgvstock.CellValidating
Dim s As String
s = Convert.ToString(dgvstock.CurrentRow.Cells("Description").Value)
Dim a As Integer = s.IndexOfAny("0123456789".ToCharArray())
If a >= 0 Then
MessageBox.Show("Enter only characters")
End If
Here we check for validation for string
|
|
|
|
|
Ah I see. Well the CellValidating event validates the content of cell that has just lost focus (well that's the way I interpret it anyway). Therefore, you have to check which cell is being validated and then do the validation.
So what I do (and this isn't necessarily the best or the only way) is use a select statement to determone which cell is being validated and then do the required validation. Something like:
Select Case dgvstock.Columns(e.ColumnIndex).Name
Case "Description"
-- do your validation for the description column here --
End select
Hope this helps.
|
|
|
|
|
You can use DataGridView's CellValidating event for this.
|
|
|
|
|
I have this code and I need to add a shortcut key (CTRL+B) for this function
If I Press (CTRL+B) this function should be executed..
How to add it ...? and how to call this function?
Here is the part of the code and I have also attached full source code with it..
Private Sub Brwse_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Brwse_Button.Click
Dim RetVal As Integer
Dim FolderName As String
FolderName = ""
RetVal = FolderBrowserDialog1.ShowDialog()
FolderName = FolderBrowserDialog1.SelectedPath
If Not (Trim(FolderName) = "") Then
LogLib_TxtBox.Text = FolderName
End If
End Sub
|
|
|
|
|
you would need to do it at the form level.
+turn keypreview on (property of the form)
+in the keydown_event, add the code to test if the control key is pressed and the b key is pressed via the 'e' argument of the routine
+if so, call brwse_button_click(nothing,nothing)
typically however, you also give the user a "hint" that the hot-key is available via a menu item or someother means. if you use the menu item, then you can assign the hot-key there.
Nathan
'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
|
|
|
|
|
Whoops! Wrong reply button...
|
|
|
|