|
thanks for your suggestions but I think you misunderstood my problem. Following is complete code and its not working:
If OpenFileDialog1.ShowDialog(Me) = DialogResult.OK Then
Dim fi As New FileInfo(OpenFileDialog1.FileName)
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=;Data Source=" & fi.DirectoryName
Dim objConn As New OleDbConnection(sConnectionString)
Dim objDataSet As DataSet = New DataSet()
objConn.Open()
Dim objCmdSelect As New OleDbCommand("select * from [Joint Restraint Assignments]" & fi.Name, objConn)
Dim objAdapter1 As New OleDbDataAdapter
objAdapter1.SelectCommand = objCmdSelect
objAdapter1.Fill(objDataSet, "test")
DataGridView1.DataSource = objDataSet.Tables(0).DefaultView
objConn.Close()
End If
I just wonder what's wrong with this code, in particular when i want to read access database file.
|
|
|
|
|
Ok, why do you need a fileinfo object ? I suspect that's what's locking your file. I did not misunderstand, your file is locked, if you like it or not.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
thanks.
what can be an alternative to fileInfo?
|
|
|
|
|
you have the path already, use System.IO.Path.GetDirectoryName and Path.GetFileName to get the pieces of the file path that you seem to need.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
sorry I didn't get it. Could you please give me an example?
|
|
|
|
|
In the System.IO namespace:
Path.GetDirectory("c:\documents\word.doc")
will return c:\documents
Path.GetFileName("c:\documents\word.doc")
will return word.doc.
The Path class is full of methods for manipulating and examining file paths
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
but my file location is not fixed. I want users to select the access database file and display a table from it into datagridview.
|
|
|
|
|
*sigh*
Dim fi As New FileInfo(OpenFileDialog1.FileName)
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=;Data Source=" & fi.DirectoryName
Dim objConn As New OleDbConnection(sConnectionString)
Dim objDataSet As DataSet = New DataSet()
objConn.Open()
Dim objCmdSelect As New OleDbCommand("select * from [Joint Restraint Assignments]" & fi.Name, objConn)
So, you take the filename from the openfiledialog and use the FileInfo object to extract the directory name and the filename. Instead, you can use the methods I gave you, to get those values from the filename property of the file dialog, directly. I am at a loss how you think what I have been saying takes away from your using a dynamic filename. If the filename was fixed, you'd type in the values in your code, not use methods to work them out, surely ?
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
that means my no need to establish a connection. Do you mean to do something like:
Dim fi As New FileInfo(OpenFileDialog1.FileName)
path.GetFileName(&fi.name)
Dim objCmdSelect As New OleDbCommand("select * from [Joint Restraint Assignments]" .....)
???
or,
path.getfilename(openfiledialog1.filename)
Dim objCmdSelect As New OleDbCommand("select * from [Joint Restraint Assignments]" .....)
|
|
|
|
|
i think i got it. But I am confused about the data source to be use in oledbconnection:
Path.GetFileName(OpenFileDialog1.FileName)
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=???")
|
|
|
|
|
Dim path as String =Path.GetFileName(OpenFileDialog1.FileName)
will give you the path in a variable. Just calling GetFileName without storing the result, does nothing.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
thanks i got it. so what should be the data source in:
Dim path1 As String = Path.GetFileName(OpenFileDialog1.FileName)
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=???")
|
|
|
|
|
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=" & path1 & "")
above code works. Thank you very very much
|
|
|
|
|
|
Are you viewing the contents of table1 in MS Access while debugging? If so, MS Access is the one that's locking the database
I are troll
|
|
|
|
|
thanks.
no i m not. the access database as well as the table is not open.
|
|
|
|
|
rajulama wrote: Dim sConnectionString As String = "..." & fi.DirectoryName
Trying to open a directory as a database?
|
|
|
|
|
rajulama wrote: Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=;Data Source=" & fi.DirectoryName
The names used in your code, you're trying to open a directory as a database. You have to give it the path to the .MDB file, not just it's parent directory.
rajulama wrote: Dim objCmdSelect As New OleDbCommand("select * from table1" & fi.Name, objConn)
On top of that, your SQL query to get the data in table1 (if it even exists in that database) is wrong. You appending the filename to the end of the SQL SELECT statement, which won't work. The filename goes in the Data Source if your connection string, not the SELECT statement.
|
|
|
|
|
Dear Coders,
At the risk of asking a stupid question, or at least a question that has been answered before many times.
How would one go about the following situation. I have an application which comprises the following:
1. VB.NET 2008 Windows Forms application
2. MySQL
3. Framework 3.5
4. Crystal Reports
5. Infragistics UI controls
6. COM controls (to connect to MySQL database)
I would like to package and deploy this application so that the user can do this without requiring much computer savvy. (Pretty much standard exam question it seems)
Currently I do the installation myself and have taught one person how to install without me. Basically the steps include:
1. Install dotnexfx35.exe (not much user intervention)
2. Install MySQL (configuration is a bit above non computer savvy)
3. Install Crystal Runtime (not much user intervention so is good)
4. Run a bat file that copies the 2 COM files to %windowsroot%\system and runs regsvr32 on each.
5. Included Infragistics the first time in a deployment
6. Install setup
What I would like to do is, create an autorun.ini and an exe on a CD that brings up a menu that can install the various components. However, how (in VB 2008) can I make an exe that does not need to be installed first?
Do you think I am going about this the right way?
|
|
|
|
|
You can't. Not in VB2008, because VB2008 needs .NET. Instead, you need to write it in C++, preferably without MFC, but you can link it so that it will work without the MFC dlls on the target machine.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Hmm, no wonder I am battling away. So now to get C++....
Thank you Christian.
|
|
|
|
|
no problem. I've been doing it that way for ages. Here is a method I wrote to run an msi, or other program, and wait for it to finish:
void CInstallerDlg::ShellExecuteAndWait(const char * path, const char * params, const char * message)
{
// Run a file and wait until it's done
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = path;
ShExecInfo.lpParameters = params;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
if (message != NULL)
{
ModelessDisplay d(this);
d.SetString(message);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
d.DestroyWindow();
}
else
{
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
}
}
Now, the really painful bit is writing code to check registry keys, etc, to work out what you need to install.....
Oh, the ModelessDisplay stuff is code that shows a message while it runs, you need to add your own class to do that, or ignore that bit.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
hi...
i think u can do the thing with setupfactory, u can search it in google..
|
|
|
|
|
i have a function... but i dont know how do i call that function to validate e-mail text box.. can u please tell me the code...
the function is as below.. please tell me how to call that.. and even where should i write the code to validate email textbox..
Imports System.Text.RegularExpressions
Function EmailAddressCheck(ByVal emailAddress As String) As Boolean
Dim pattern As String = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
Dim emailAddressMatch As Match = Regex.Match(emailAddress, pattern)
If emailAddressMatch.Success Then
EmailAddressCheck = True
Else
EmailAddressCheck = False
End If
End Function
|
|
|
|
|
Wow. What this tells me is that you're able to use google to find code, but don't have the most basic idea of what it does. I suggest reading a VB.NET book or two before you do anything else.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|