|
Member 3936356 wrote: _command.CommandText = "SELECT * INTO [MS Access;Database=somefile.mdb].[accesstbname] FROM [Sheet1$]"
In order to do what you want, you have to retrieve the data from the Excel sheet into a DataTable, iterate over the rows in the DataTable, verify that the row's ID is NOT already in the database, then execute an INSERT query to add the new row to the table if it' doesn't already exist.
|
|
|
|
|
Thanks for you suggestions. But still as i am a newbie i donot have any idea about checking excel sheet rows against database unique id field and insert ones that does not exist. I expect some help in coding.
|
|
|
|
|
Can someone please look at this and make some suggestions on how to improve the performance of this snippet this is killing one of our apps.
Private Function fbParseParameters(ByVal sArgs() As String) As Boolean
Dim tTemp As String
'
fbParseParameters = True
Dim iII As Integer = 0
If sArgs.Length > 0 Then
' each parameter is broken into a seperate array item.
While iII < sArgs.Length
tTemp = sArgs(iII).ToUpper
' look at the parms, and figure out which is which...
If tTemp.IndexOf("DATABASEHOST=") > 0 Then
myConnectionInfo.tDatabaseHost = tTemp.Substring(tTemp.IndexOf("=") + 1, _
(tTemp.Length - (tTemp.IndexOf("=") + 1)))
End If
If tTemp.IndexOf("USERNAME=") > 0 Then
myConnectionInfo.tUserName = tTemp.Substring(tTemp.IndexOf("=") + 1, _
(tTemp.Length - (tTemp.IndexOf("=") + 1)))
End If
If tTemp.IndexOf("USERNUMBER=") > 0 Then
myConnectionInfo.lUserNumber = tTemp.Substring(tTemp.IndexOf("=") + 1, _
(tTemp.Length - (tTemp.IndexOf("=") + 1)))
End If
If tTemp.IndexOf("PASSWORD=") > 0 Then
myConnectionInfo.tPassword = tTemp.Substring(tTemp.IndexOf("=") + 1, _
(tTemp.Length - (tTemp.IndexOf("=") + 1)))
End If
If tTemp.IndexOf("LOCALE=") > 0 Then
myConnectionInfo.tCurrentLocaleCode = tTemp.Substring(tTemp.IndexOf("=") + 1, _
(tTemp.Length - (tTemp.IndexOf("=") + 1)))
End If
If tTemp.IndexOf("LOCALEDESCR=") > 0 Then
myConnectionInfo.tCurrentLocale = tTemp.Substring(tTemp.IndexOf("=") + 1, _
(tTemp.Length - (tTemp.IndexOf("=") + 1)))
End If
If tTemp.IndexOf("MODULE=") > 0 Then
strApplicationInfo.tCurrentModule = tTemp.Substring(tTemp.IndexOf("=") + 1, _
(tTemp.Length - (tTemp.IndexOf("=") + 1)))
End If
If tTemp.IndexOf("REPORT=") > 0 Then
strApplicationInfo.tReport = tTemp.Substring(tTemp.IndexOf("=") + 1, _
(tTemp.Length - (tTemp.IndexOf("=") + 1)))
End If
If tTemp.IndexOf("CLIENT=") > 0 Then
strSystemInfo.lCurrentClient = tTemp.Substring(tTemp.IndexOf("=") + 1, _
(tTemp.Length - (tTemp.IndexOf("=") + 1)))
End If
If tTemp.IndexOf("COMPONENTNUM=") > 0 Then
strSystemInfo.lComponentNum = tTemp.Substring(tTemp.IndexOf("=") + 1, _
(tTemp.Length - (tTemp.IndexOf("=") + 1)))
End If
If tTemp.IndexOf("ISTHERAPY=") > 0 Then
Dim tTemp2 As String
tTemp2 = tTemp.Substring(tTemp.IndexOf("=") + 1, _
(tTemp.Length - (tTemp.IndexOf("=") + 1)))
If tTemp2 = "-1" Or tTemp2 = "0" Or tTemp2 = "1" Or tTemp2.ToUpper = "TRUE" Or tTemp2.ToUpper = "FALSE" Then
strSystemInfo.bIsTherapy = CBool(tTemp2)
End If
End If
If tTemp.IndexOf("PLANTYPE=") > 0 Then
strSystemInfo.tPlanType = tTemp.Substring(tTemp.IndexOf("=") + 1, _
(tTemp.Length - (tTemp.IndexOf("=") + 1)))
End If
If tTemp.IndexOf("GRIDMODE=") > 0 Then
strSystemInfo.tGridMode = tTemp.Substring(tTemp.IndexOf("=") + 1, _
(tTemp.Length - (tTemp.IndexOf("=") + 1)))
End If
If tTemp.IndexOf("HEADERNUMBER=") > 0 Then
strSystemInfo.lHeaderNum = tTemp.Substring(tTemp.IndexOf("=") + 1, _
(tTemp.Length - (tTemp.IndexOf("=") + 1)))
End If
If tTemp.IndexOf("DISCIPLINE=") > 0 Then
strSystemInfo.lDisciplineNum = tTemp.Substring(tTemp.IndexOf("=") + 1, _
(tTemp.Length - (tTemp.IndexOf("=") + 1)))
End If
If tTemp.IndexOf("THERAPISTNUM=") > 0 Then
strSystemInfo.lTherapistNum = tTemp.Substring(tTemp.IndexOf("=") + 1, _
(tTemp.Length - (tTemp.IndexOf("=") + 1)))
End If
iII += 1
End While
Else
fbParseParameters = False
Exit Function
End If
' We must at least have username, password, and database host in order to do anything...
If myConnectionInfo.tUserName = String.Empty Or _
myConnectionInfo.tPassword = String.Empty Or _
myConnectionInfo.tDatabaseHost = String.Empty Then
fbParseParameters = False
End If
End Function
Here is an example of the parm string
/DATABASEHOST=TEST/DATABASENAME=TEST /USERNAME=TEST /PASSWORD=TEST /LOCALE=GW /LOCALEDESCR=Glenwood /MODULE=CL /REPORT=TRMonthlyAttendance
Here is where it is loaded into the array
' must format these into an array ...
tParms = txtParm.Text.Split("/")
Dim iII As Integer
For iII = 1 To tParms.Length - 1
tParms(iII) = Trim("/" & tParms(iII))
Next
Humble Programmer
|
|
|
|
|
You're using tTemp.Substring(tTemp.IndexOf("=") + 1 multiple times in each block. If you defined your search strings as constants, you could skip this. For example:
private const DATABASEHOST_ARG As String = "DATABASEHOST="
...
If tTemp.IndexOf(DATABASEHOST_ARG) > 0 Then
myConnectionInfo.tDatabaseHost = tTemp.Substring(DATABASEHOST_ARG.Length(), _
(tTemp.Length - DATABASEHOST_ARG.Length())
End If
I didn't compile, so formatting may be off - and make sure you check to see that I've got the Substring starting index correct. I'm pretty sure that the '+ 1' is no longer necessary.
Simply rinse and repeat for your other blocks and your helpful compiler should replace a lot of "IndexOf" operations with simple math!
|
|
|
|
|
Thank you I will add that with some other things that I have done to it and that should help.
Humble Programmer
|
|
|
|
|
Split the string with delimiter "/" into string array, then from there split with delimiter "=" then put the pair into HashTable.
Then assign your class from the HashTable (check for empty), ie
strSystemInfo.lTherapistNum = hashTable["THERAPISTNUM"].Value;
|
|
|
|
|
In VB6 I used to use the following to automatically select an item in a listbox when a user types in a textbox:
[Module]
Public Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As String) As Long
Public Const LB_SELECTSTRING = &H18C
...}
[Form]
Private Sub txtForLstAllUsers_Change()
If txtForLstAllUsers.Text <> "" Then
SendMessage lstAllUsers.hwnd, LB_SELECTSTRING, -1, txtForLstAllUsers.Text
End If
End Sub
I tried copying and pasting into a VB .Net application and I am getting the following error:
"hwnd is not a member of Systems.Windows.Forms.Listbox."
Also, I noticed there is no Change event for textboxes in .Net.
Can anyone tell me how to re-create this functionality in a .Net project?
Any help will be greatly appreciated!!
|
|
|
|
|
I think the property is now Handle (lstAllUsers.Handle). And try the textbox's TextChanged event.
|
|
|
|
|
Thanks for your response, JZ. I will give it a try.
I did, however, in the meantime find something that works rather well, in lieu of the listbox -
I used a combobox and selected "simple" as the combo type. That put the textbox right over a drop down that's visible; the control looking like a listbox with a textbox on top. I don't have the project in front of me, but I think I may have set another property for the combo that automatically auto selects when someone types in the textbox part of the combo.
|
|
|
|
|
Hi There
This is my first post, I need help
I've a Datagridview filling from tbx and combobox, I want to put a Checkbox in each row (I don't how) so I want to delete a row checked from the datagridview
Please help, I very rookie
I'm doing this...
Public DRow As DataRow<br />
Public Carrito As New DataTable("Detalle")<br />
<br />
Sub Configuratabla()<br />
Dim DC0 As New DataColumn("Item", System.Type.GetType("System.Int64"))<br />
Dim DC1 As New DataColumn("Cantidad", System.Type.GetType("System.Int64"))<br />
Dim DC2 As New DataColumn("Detalle", System.Type.GetType("System.String"))<br />
Dim DC3 As New DataColumn("Valor", System.Type.GetType("System.Int64"))<br />
Dim DC4 As New DataColumn("Descuento", System.Type.GetType("System.Int64"))<br />
Dim DC5 As New DataColumn("Total", System.Type.GetType("System.Int64"))<br />
<br />
'DC4.Expression = "cantidad * Valor "<br />
With Carrito.Columns<br />
.Add(DC0)<br />
.Add(DC1)<br />
.Add(DC2)<br />
.Add(DC3)<br />
.Add(DC4)<br />
.Add(DC5)<br />
<br />
End With<br />
<br />
GrillaDetalle.DataSource = Carrito<br />
<br />
End Sub<br />
<br />
<br />
<br />
DRow = Carrito.NewRow()<br />
DRow(0) = Carrito.Rows.Count + 1 'Item<br />
DRow(1) = CInt(TbxCan.Text) 'Cantidad<br />
DRow(2) = CbxPro.SelectedItem 'Detalle<br />
DRow(3) = Valor1<br />
DRow(4) = CbxDes.SelectedItem 'Descuento<br />
DRow(5) = (CInt(TbxCan.Text)<br />
Carrito.Rows.Add(DRow)
|
|
|
|
|
hi,
i hope that this can help you :
1-to add checkboxcolumn:
Dim mycolumn As New DataGridViewCheckBoxColumn
mydatagridview.Columns.Insert(0, mycolumn)
2-to delete row:
if mydatagridview.SelectedRows(i).Cells(0).Value=true then
mydatagridview.rows.removeat(indexofmayrow)
end if
Il principe
|
|
|
|
|
...or simply add another Column of Type Boolean to your DataTable
Dim DC6 As New DataColumn("Delete", System.Type.GetType("System.Boolean"))
.Add(DC6)
'***initialize Column
DRow(6) = false
After Binding the DataTable to the DataGridView it will automatically create a CheckBoxColumn out of the DataType Boolean.
|
|
|
|
|
I am writing a VB 6 program that shd run on the network. A user has to login before using the program. Now, I want to prevent multiple user login using one user account. It shdn't allow or prevent a user to login whilst his/her account is in use(the same Cafe Timer Login.
Also, how do i make the client send Username (Text1.Text) and Password (Text2.Text) to the server and make the server put them into the Vars strUser, and strPass?
Please, can anyone help me with this? I would be very grateful if you could help me with this.
|
|
|
|
|
kingascona wrote: I am writing a VB 6 program that shd run on the network. A user has to login before using the program. Now, I want to prevent multiple user login using one user account. It shdn't allow or prevent a user to login whilst his/her account is in use(the same Cafe Timer Login.
You have to track the user logins AND logouts. When the user attempts to log in, you're code has to check to see if the ID is already logged in and, if so, deny the new login until the old login is logged out. You'd normally track this data in your database users table, or some other session tracking table.
But, there's a catch. What if the user's machine crashes and is forced to reboot without logging out of your app? You need some kind of tool that can clear the now-stuck login. Say the last login was 30 minutes ago, but there hasn't been any activity for the last 15. You need to be able to detect and idle session and automatically log it out at some point. Or write some other tool that an administrator can use to clear the login. Otherwise, the user who had to reboot their machine without properly logging out will never be able to log back in.
|
|
|
|
|
I am able to use SQL commands to access any table & any columns in MS access (or in Excel) table. However, when I try to search columns with spaces (ie: Employee IDNumber, Employee Name, ...) then I have errors
If I change to Employee_IDNumber, Employee_Name then it is OK
<br />
Dim m_sModification As String = "UPDATE [Table Name$] SET Employee_Name = 'Jonny White' WHERE Employee_IDNumber = '12345678'"<br />
<br />
Dim conn1 As New System.Data.OleDb.OleDbConnection(m_sConnection1)<br />
conn1.Open()<br />
But I have the MS Access (or Excel) tables having Column Headers with spaces between, I try to avoid changing all of them with xxxxx_xxxxx
Do we have other ways to deal with this issue?
Thank in-advanced
modified on Thursday, April 3, 2008 10:34 AM
|
|
|
|
|
You have to enclose and table names and columns with spaces, or names with the potential to have spaces, in square brackets ([]). Like this:
UPDATE [Table Name$] SET [Employee Name] = 'Jonny White' WHERE [Employee IDNumber] = '12345678'
But, keep in mind that having spaces in table and column names is considered bad practice. Avoid doing this if at all possible.
|
|
|
|
|
Hi Dave,
It works! I am awared of your comments, however the existed files that has columns with spaces being done long time ago & I am not allow to remove spaces
Many thanks
|
|
|
|
|
Hello everyone...i need some help!!!
I am currently working on a project and have stumbled across a problem. I wish to display data from a database into a combo box on a VB.net form. I can add data on forms that saves in the database but you cannot view the newly entered data in the combo boxs on the VB forms. Is there a code that refreshes the database connection every time new data is entered on the VB forms? Note that the data i wish to display in the combo box is entered on a seperate form on VB.
|
|
|
|
|
You have to reload it by clearing it, and then running whatever code you loaded it with before. Loading a combobox with database data via a connection doesn't keep that connection open and refresh on its own. You essentially grab a copy of the data and hold onto it on the screen. So if the data changes you have to hit the database again to see the new data.
Hope this helps.
|
|
|
|
|
If you have updated data that is reflected in a ComboBox, then you have to re-fetch that data to get it into the ComboBox. Depending on who you fetched that data and bound the ComboBox to it the first time, all you should need to do is run that code again to re-fetch the new data.
|
|
|
|
|
i am working on word macro in which i have to select few heading1 complete content and paste it into other document.
In the document in every heading 1 i have placed bookmarks for start and end . So how to pick up the text .
Private Sub CommandButton3_Click()
Dim a As String
Dim iCnt As Integer
a = ""
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 1")
Selection.MoveDown Unit:=wdWindow, Count:=1, Extend:=wdExtend
'With ActiveDocument.Select
'With Selection.SetRange Start:=Selection.Start, End:=ActiveDocument.Content.End
Dim Label As String
Do While Selection.Find.Execute
With Selection.Find
fndrepl "<#T"
If .Find.Found Then
iCnt = .MoveEndUntil("#>")
If iCnt = 0 Then
MsgBox "No closing tag found", vbOKOnly, "Error..."
Exit Do
End If
.MoveRight wdCharacter, 2, wdExtend
a = Selection.Text
End If
End With
Loop
End Sub
|
|
|
|
|
how to encrypt the connectionstring tag and other tag wen needed in the appconfig file ..how an app.config file is encrypted.
|
|
|
|
|
You don't encrypt the app.config file. You encrypt the values of your sensitive tags, like a ConnectionString. Read this[^].
|
|
|
|
|
hi all
iam making a project in which i have to read 5v(logic 1) from one pin
of parallel port and then from second pin,then measure the time
interval between them.Then i have a fixed distance and so have to
calculate the speed.
Please help me how to write the code and should i write in vb??.
|
|
|
|
|
Read this[^] little article here on CP. The code is written in C#, but is easily translatable to VB.NET.
|
|
|
|