|
Does anyone know how to insert all items in a listbox into an access database table?
|
|
|
|
|
I'm not on a dev pc at the moment so can't supply any code samples or anything but I'd imagine that you'd probably copy the contents of the listbox to a dataset & then pass the dataset back to the database.
There are other solutions but this is probably one of the easiest. What exactly is your problem?
I'm sooooo happy today!
|
|
|
|
|
I have a program that will allow me to search for files and add the files to a listbox by entering the file folder path in textbox1 and extension in textbox2. I want the files that are in the listbox to be added to an access table called tblRestrFileReport under ExcludeFileName column.
|
|
|
|
|
Then I stand by my OP. Do you know how to work with ADO.NET & datasets? Here is an article on ADO.NET that may prove useful to you.
|
|
|
|
|
how to show video properties.
i use Grapehdit and add filter for capture card,went Right click select filter properties. it show properties...,but i want show properties form in my project,went i click button...
how to coding it
use directshow
thank you
|
|
|
|
|
I have a program that will allow me to enter a folder path into a textbox and file extension into a textbox. Once the path and the extension are typed in, click the search button and the files within the folder specified and the extension entered will be added to listbox1. Also, I have a access table named tblExclude that contains excluded files. In the program, if the folder path in tblExclude is equal to the path entered into the textbox then the filename will be added to listbox2.
For example:
'If the following 2 files are in tblExclude:
ExcludeFilePath: C:WINDOWS\Media
ExcludeFileName: recycle.wav
ExcludeFilePath: C:WINDOWS\Media
ExcludeFileName: recycle2.wav
'Then when you enter your path in Textbox1:
C:WINDOWS\Media
both of the following files that are in tblExclude are added to listbox 2:
recycle.wav
recycle2.wav
But I have a problem. I am only searching for excluded files by the folder path. I need to be able to search for excluded files by the path and extension. Because right now, if I enter folder path "C:\WINDOWS\Media" into textbox1 and click the search button the files in tblExclude will be displayed in listbox 2 without entering the extension in textbox. So I need to be able to search for files in tblExclude by path and ext.
Here is my code:
Dim dt As DataTable<br />
<br />
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click<br />
'Get the entered file paths and patterns<br />
Dim enteredFilePaths As String() = TextBox1.Text.Split(New String() {";"}, StringSplitOptions.RemoveEmptyEntries)<br />
Dim patterns As String() = TextBox2.Text.Split(New String() {";"}, StringSplitOptions.RemoveEmptyEntries)<br />
<br />
'Declare a string array to store the file paths that are not found in the database<br />
Dim filePaths() As String = Nothing<br />
<br />
Dim dv As DataView = dt.DefaultView<br />
dv.Sort = "ExcludePath ASC"<br />
<br />
For Each path As String In enteredFilePaths<br />
'Check to make sure the file path does not have "\" as it's last character.<br />
If path.LastIndexOf("\") = path.Length - 1 Then<br />
path = path.Substring(0, path.Length - 1)<br />
End If<br />
<br />
Dim rows As DataRowView() = dv.FindRows(path)<br />
If rows.Length > 0 Then<br />
For Each row As DataRowView In rows<br />
'It was found in the database, display it in the listbox.<br />
Me.ListBox2.Items.Add(row.Item("ExcludeFileName"))<br />
Next<br />
Else<br />
'It was not found in the database<br />
Dim i2 As Integer = 0<br />
If Not filePaths Is Nothing Then<br />
i2 = UBound(filePaths) + 1<br />
End If<br />
<br />
'Resize the array<br />
ReDim filePaths(i2)<br />
<br />
'Add the path to the array<br />
filePaths(i2) = path<br />
End If<br />
Next<br />
GetDirectoryContents(enteredFilePaths, patterns)<br />
<br />
Private Sub GetDirectoryContents(ByVal dirs() As String, ByVal patterns() As String)<br />
'Declare variable.<br />
Dim dDir As DirectoryInfo<br />
<br />
'Search directory for files and add to the listbox.<br />
For Each sDir As String In dirs<br />
If Not Directory.Exists(sDir) Then Continue For<br />
dDir = New DirectoryInfo(sDir)<br />
For Each ext As String In patterns<br />
For Each fi As FileInfo In dDir.GetFileSystemInfos("*." & ext)<br />
ListBox1.Items.Add(fi.Name)<br />
Next<br />
Next<br />
Next<br />
End Sub<br />
<br />
Private Sub LoadData()<br />
'Create a datatable to store data<br />
<br />
dt = New DataTable("tblExclude")<br />
Dim colExFileID As New DataColumn("ExcludeID")<br />
Dim colExFilePath As New DataColumn("ExcludePath")<br />
Dim colExFileName As New DataColumn("ExcludeFileName")<br />
DataGridView1.DataSource = dt<br />
<br />
dt.Columns.AddRange(New DataColumn() {colExFileID, colExFilePath, colExFileName})<br />
<br />
Dim myConnString As String = "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" & Application.StartupPath & "\File.mdb"<br />
Dim myConnection As New OleDbConnection(myConnString)<br />
myConnection.Open()<br />
Dim strSQL As String = "SELECT * FROM tblExclude"<br />
<br />
Dim dAdapter As New OleDbDataAdapter()<br />
dAdapter.SelectCommand = New OleDbCommand(strSQL, myConnection)<br />
<br />
'Retrieve the data from the database and load the DataTable with it<br />
dAdapter.Fill(dt)<br />
<br />
myConnection.Close()<br />
<br />
End Sub<br />
<br />
Private Sub SearchFileForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
LoadData()<br />
<br />
End Sub
Any ideas?
jds1207
|
|
|
|
|
Hi,
I know how to get/set a class property using the function "CallByName".
Do you know a way to do the same with global variables ?
Or, alternatively, is there a way (in VB.NET) to have an instance of a class, as in VB6 Global-Multiuse classes (calling directly the method/property, without the name of the class) ?
Thanks.
Peace!
|
|
|
|
|
advansis wrote: Do you know a way to do the same with global variables ?
There's no such thing as a true global variable in .NET. You can simulate one by making it a Shared member of a class though, such like:
Public Class Globals
Public Shared myGlobal As Integer
advansis wrote: Or, alternatively, is there a way (in VB.NET) to have an instance of a class, as in VB6 Global-Multiuse classes (calling directly the method/property, without the name of the class) ?
Creating an instance of a class without knowning the name of the class. Ummmm, no. The compiler can't read your mind. Or did I completely miss something here?
|
|
|
|
|
It looks like he's trying to bring back late-binding. As a disclaimer, I suggest avoiding this technique when possible, as it's slow, inefficient, and prone to runtime errors.
Get the type of your object (obj.GetType() or TypeOf obj), then call GetProperty() on that (Check MSDN for the syntax and parameters). That'll get you a PropertyInfo object, which you can use to access the property.
Remember that this is a LOT slower than just calling object.property, so if you need to call it a few thousand times quickly, you might need to redesign.
|
|
|
|
|
Ian Shlasko wrote: It looks like he's trying to bring back late-binding. As a disclaimer, I suggest avoiding this technique when possible, as it's slow, inefficient, and prone to runtime errors.
Yeah, I was thinking the same thing, though I didn't want to jump to conclusions.
Ian Shlasko wrote: Get the type of your object (obj.GetType() or TypeOf obj), then call GetProperty() on that (Check MSDN for the syntax and parameters). That'll get you a PropertyInfo object, which you can use to access the property.
Remember that this is a LOT slower than just calling object.property, so if you need to call it a few thousand times quickly, you might need to redesign.
Along the lines of 30-50 times as long as doing it the "old fashioned" way - direct assignment.
|
|
|
|
|
I am measuring a string with the following code. The output string by no choice of mine is measured as 14 pt and I need to know some type of equivalent to that in em.
Dim stringSize As New SizeF
Dim g As Graphics
Using myFont As New Font("Courier", 1)
Using myBitmap As New Bitmap(1, 1)
g = Graphics.FromImage(myBitmap)
stringSize = g.MeasureString(outputString), myFont)
End Using
End Using Does anyone know of a solution here? The only equivalency I can find between em and other font measurements was a site that said a font size of 10 px would be 1 em and 11 would be 1.1 and so on.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
Hi,
try the function "TextRenderer.DrawText" that returns the measure in pixels.
Hope this helps.
ADVANSIS
Peace!
|
|
|
|
|
Hi,
I have Three column in report A, B ,C the column C = A+b
I used formula
I need summrized column C in footer repoty when I used sum function appear this message
This field cannot be summarized
pls help me?
|
|
|
|
|
hi,
check whether datatype of Column A or Column B is numeric or not. I think Both A and B is not numeric
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
|
|
|
|
|
Anyone knows how to set media format when ripping CD? e.i. WMA, MP3...
and also the bitrate?
Thanks.
|
|
|
|
|
can i insert the single quotes programatically into the database.
|
|
|
|
|
Hi,
Yes u can add quotes just by replacing single quote with double quote. Replacing will add only single quote in database.
Example:
strName=Xyz's
"Insert into table1(Name) Values('" & Replace(strName,"'","''") & "')"
Regards
Ali Raza
|
|
|
|
|
|
While the previous poster did answer your question the result is very poor and potentially dangerous advice.
That way SQL Injection Attacks lay. Please read SQL Injection Attacks and Tips on How To Prevent Them[^] and then change your code to use parameterised queries rather than string substitution.
|
|
|
|
|
That way SQL Injection Attacks lay - While you did answer the OP's question, the better answer would have been to replace string injection with parameterised queries. That way you don't have to worry about apostrophes in the data and you help prevent SQL Injection Attacks.
Please read SQL Injection Attacks and Tips on How to Prevent Them[^]
|
|
|
|
|
yes, you can.
try following format
str="insert into table1 values (" & """" & var1 & """" & ")"
where var1 may contain single & double quotes.
hope this helps
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
|
|
|
|
|
|
Not another one. Please please please! Will people please learn about SQL Injection Attacks!
If you see someone asking a question like this again the best course is to guide them towards parameterised queries as it helps prevent SQL Injection Attacks. Any answer that still involved injecting data in to a SQL String is potentially dangerous.
Please read SQL Injection Attacks and Tips on How to Prevent Them[^]
|
|
|
|
|
Yes, you don't want an angry Scot after you!
__________________
Bob is my homeboy.
|
|
|
|
|
"If it's not Scottish - It's CR****P!"
|
|
|
|