从打开文件对话框路径中选择 [英] select from open file dialog path
本文介绍了从打开文件对话框路径中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个select语句来选择要插入数据库的文件。
i have this select statement to select the file to insert into database.
Dim query As String = "INSERT INTO test (School, Campus, AdminNo, ModuleCode, ModuleGrp) " & _
"SELECT F1 as School, F2 as Campus, F3 as AdminNo, F4 as ModuleCode, F5 as ModuleGrp FROM [Text;HDR=NO;DATABASE=J:\FYP\;].[SEG1.txt]"
i我可以将select从文件更改为openfiledialog路径/文件吗?
i尝试过:
i can i change the select from file to the openfiledialog path/file?
i tried:
Dim query As String = "INSERT INTO test (School, Campus, AdminNo, ModuleCode, ModuleGrp) " & _
"SELECT F1 as School, F2 as Campus, F3 as AdminNo, F4 as ModuleCode, F5 as ModuleGrp FROM [Text;DATABASE=" & System.IO.Path.GetDirectoryName(Me.OpenFileDialog1.FileName) & ";HDR=NO].[" & Me.OpenFileDialog1.SafeFileName & "]"
提前致谢!
Thanks in advance!
推荐答案
是,你可以 OpenFileDialog [ ^ ],但以不同的方式,使用字符串变量而不是OpenFileDialog属性。
请创建新的WindowsApplication项目并在表单上放置一个按钮,然后双击它。复制并粘贴以下代码:
Yes, you can ust it OpenFileDialog[^], but in different way, using string variable instead OpenFileDialog properties.
Please, create new WindowsApplication project and put one button on the form, then double-click on it. Copy and paste below code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ofd As OpenFileDialog = Nothing
Dim sFullFileName As String = String.Empty
Try
ofd = New OpenFileDialog()
With ofd
.InitialDirectory = Environment.SpecialFolder.MyDocuments
.Multiselect = False
.DefaultExt = "txt"
.Filter = "txt files (*.txt)|*.txt"
If .ShowDialog = Windows.Forms.DialogResult.Cancel Then Exit Try
sFullFileName = .FileName
End With
MsgBox("Directory name: '" & System.IO.Path.GetDirectoryName(sFullFileName) & "'" & vbCr & _
"Short file name: '" & System.IO.Path.GetFileName(sFullFileName) & "'", MsgBoxStyle.Information, "Information...")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...")
Finally
ofd = Nothing
End Try
End Sub
End Class
尝试这个...
try to this...
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
strfilename = openFileDialog1.InitialDirectory + openFileDialog1.FileName;
}
这篇关于从打开文件对话框路径中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文