|
Hi,
I have to do updates to my mdb access database, which has 2 column, user_name and user_pwd.
I have followed the suggestion from MSDN, but I don't know it still got error when excuting update().It says "Update command" or "Insert Command" to have connection object...
Can someone give me some hints or point out to me that What I missed?
Here is my code:
<br />
Dim connStr As String = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\me.mdb")<br />
Dim sqlStr As String = "SELECT * FROM wpLogin"<br />
Dim dt As New DataTable()<br />
Dim dataAdapter As OleDbDataAdapter<br />
Dim ODBconn As OleDbConnection<br />
<br />
<br />
Public Function CreateDataAdapter(ByVal selectCommand As String, ByVal connection As OleDbConnection) As OleDbDataAdapter<br />
<br />
<pre>Dim adapter As OleDbDataAdapter = New OleDbDataAdapter(selectCommand, connection)<br />
<br />
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey<br />
<br />
' Create the commands.<br />
adapter.InsertCommand = New OleDbCommand( _<br />
"INSERT INTO wpLogin (user_name, user_pwd) " & _<br />
"VALUES (?, ?)")<br />
<br />
adapter.UpdateCommand = New OleDbCommand( _<br />
"UPDATE wpLogin SET user_name = ?, user_pwd = ? " & _<br />
"WHERE user_name = ?")<br />
<br />
adapter.DeleteCommand = New OleDbCommand("DELETE FROM wpLogin WHERE user_name = ?")<br />
<br />
' Create the parameters.<br />
adapter.InsertCommand.Parameters.Add( _<br />
"@user_name", OleDbType.Char, 50, "user_name")<br />
adapter.InsertCommand.Parameters.Add( _<br />
"@user_pwd", OleDbType.Char, 50, "user_pwd")<br />
<br />
adapter.UpdateCommand.Parameters.Add( _<br />
"@user_name", OleDbType.Char, 50, "user_name")<br />
adapter.UpdateCommand.Parameters.Add( _<br />
"@user_pwd", OleDbType.Char, 50, "user_pwd")<br />
<br />
adapter.DeleteCommand.Parameters.Add( _<br />
"@user_name", OleDbType.Char, 50, "user_name").SourceVersion = _<br />
DataRowVersion.Original<br />
<br />
Return adapter<br />
</pre>End Function<br />
<br />
<br />
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click<br />
<pre>'Displays the table's data in the data grid<br />
'Clear the current contents of the table<br />
dt.Clear()<br />
'Fill the data table with data from the database<br />
'Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connStr)<br />
ODBconn = New OleDbConnection(connStr)<br />
dataAdapter = CreateDataAdapter(sqlStr, ODBconn)<br />
dataAdapter.Fill(dt)<br />
'dataAdapter.Dispose()<br />
'Display the table in the data grid<br />
dgDisplay.DataSource = dt</pre><br />
End Sub<br />
<br />
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click<br />
'Save the tables's changes back to the database<br />
<pre>Dim changes As Integer<br />
<br />
<br />
'Update the database with changes from the data table<br />
changes = dataAdapter.Update(dt)<br />
'dataAdapter.Dispose()<br />
'Display the number of changes made<br />
If changes > 0 Then<br />
MsgBox(CStr(changes) & " changed rows were stored in the database.")<br />
Else<br />
MsgBox("No changes made.")<br />
End If</pre> <br />
End Sub<br />
<br />
Private Sub UserManager_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing<br />
<pre>dataAdapter.Dispose()</pre><br />
End Sub<br />
End Class<br />
-- modified at 23:08 Friday 11th May, 2007
|
|
|
|
|
I have frame and listview1. I want to hide the frame when i click(left click or right click) on white area of listview1 where is there is no data (As shown in attched pic).could any one show me how this can be done?Thanks
<br />
Private Sub ListView1_Click()<br />
gstrSomething = ListView1.SelectedItem.SubItems(4)<br />
gstrSomethingElse = ListView1.SelectedItem.Text<br />
Frame1.Visible = True<br />
<br />
End Sub<br />
<br />
<br />
Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)<br />
<br />
Dim lvwItem As ListItem<br />
If Button = vbRightButton Then<br />
Set lvwItem = ListView1.HitTest(x, y)<br />
If Not lvwItem Is Nothing Then<br />
<br />
Frame1.Visible = True<br />
<br />
lvwItem.Selected = True<br />
PopupMenu mnuEdit<br />
Else<br />
Frame1.Visible = False<br />
End If<br />
End If<br />
<br />
<br />
End Sub<br />
<br />
|
|
|
|
|
have my program working but need to be able to search for files of multiple file types and search for multiple drives at the same time. Right now I can only search for one files type by typing the extension into a textbox. To search for the drive, i created a BrowseFolderDialog to search folder on a specific drive and the path is displayed in a textbox. So I have two question: Is there a way for me to search for multiple file types by typing the extensions in the textbox at the same time? Is there a way to search for more than one drive in a text box at one time?
Here is some code:
Private Sub GetDirectoryContents()
Dim FilePattern As String = "*." & TextBox2.Text.Trim
Dim sdir As String = TextBox1.Text.Trim
Dim dDir As New DirectoryInfo(sdir)
Dim fi As FileSystemInfo
For Each fi In dDir.GetFileSystemInfos(FilePattern)
ListBox1.Items.Add(fi.Name)
Next
End Sub
This is the class I created to search for the folders:
Dim MyBrowseFolder As New FolderBrowser()
Public Function ShowDialog(ByVal browseFolderTitle As String)
With MyBrowseFolder
.Style = FolderBrowserStyles.BrowseForComputer
.StartLocation = FolderBrowserFolder.MyComputer & .StartLocation = FolderBrowserFolder.MyDocuments
'Dialog box title
.Description = browseFolderTitle
.ShowDialog()
'Return the folder path.
ShowDialog = .DirectoryPath
jds1207
|
|
|
|
|
let the users type multiple extensions to a textbox seperated by commas. create a thread to search a specific extension in your path and then run multiple instances of that thread with one extension in each thread. since you have the code convert the function you are using to a thread
Vilsad P P
MCTS (Windows Applications) .Net 2.0
|
|
|
|
|
How do I create a thread?
|
|
|
|
|
|
Is this correct because its still not working?
Dim MyThread As New System.Threading.Thread(AddressOf GetDirectoryContents)
MyThread.Start()
It may seem simple but I've never worked with threads before.
|
|
|
|
|
Threading is a advanced topic to understand in a few minuts. i thing you should search in MSDN and a overall knowledge about threads and threads in vb.net first. then write your program, thread functions are not like ordinary functions, and when handling you should be more cautious because you may end up in thread locks. but threads are good practice if you want your program run in a faster way (by deviding the work load to multiple threads so you can get all the work done simultaniously)
jds1207 wrote: Dim MyThread As New System.Threading.Thread(AddressOf GetDirectoryContents)
MyThread.Start()
there is no problem with your code, what is the error you are getting ?
Vilsad P P
MCTS (Windows Applications) .Net 2.0
|
|
|
|
|
Error: Cross-thread operation not valid: Control 'ListBox1' accessed from a thread other than the thread it was created on.
Right now, when I do the file search I type the file type in the textbox(txt) and the files with those types are displayed in a listbox. I want to change it so I can type in for example, txt, bmp, log into the textbox and display all of those file types in the listbox together. Is threading the only solution for this?
|
|
|
|
|
you can't directly use the objects you created in your application inside the thread,
you can do your multiple extension search without a thread too, but you will have to search one by one extensions,but this will consume some time
Vilsad P P
MCTS (Windows Applications) .Net 2.0
|
|
|
|
|
I want to build an application in Visual Basic, integrating GIS technology which includes maps, and databases. I am a student who cant afford all the nice packages please help.
|
|
|
|
|
I wrote a GIS application in C++ for my final year project at university. Technology has moved on a lot since then and it would be much easier nowadays. So go for it. You can download Visual Studio 2005 Express Edition for free and that's all that would be needed.
If you want a head start you could look for open source GIS projects. I'm sure I saw one on CodePlex a couple of months back - that might be useful for you.
|
|
|
|
|
my problem is,showing one arrow mark and plus sign in datagrid,if i click the plus sign means,the table come like tree node,then i click table means,then values are display from sql database with header name as new dataset.so i want to hide that arrow mark,plus sign and new dataset.how to hide these?i want only values display without that arrow mark,plus sign.
|
|
|
|
|
The Arrow you can get rid of by not showing the row headers, there is a property that you can set this, and the plus you can get rid of by only binding a DataTable to the datagrid, and not a DataSet. so instead of Datagrid1.datasource = dataset1 use datagrid1.datasource = dataset1.tables(0)
|
|
|
|
|
Setting permissions for new folders .NET 2.0 8mins ago
Hello,
I have seen the vb.net sample code on msdn for setting permissions for new folders (below), but still have some questions about it. I am writing a program that creates new folders, and sets permissions for the new folders. An Access database contains the permissions for each group. I have found very little information and examples for this subject. If anyone is familiar with security and the .NET 2.0 framework, I would greatly appreciate the help. Thank you for reading this message!
Imports System
Imports System.IO
Imports System.Security.AccessControl
Module DirectoryExample
Sub Main()
Try
Dim DirectoryName As String = "TestDirectory"
Console.WriteLine("Adding access control entry for " + DirectoryName)
' Add the access control entry to the directory.
AddDirectorySecurity(DirectoryName, "MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow)
Console.WriteLine("Removing access control entry from " + DirectoryName)
' Remove the access control entry from the directory.
RemoveDirectorySecurity(DirectoryName, "MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow)
Console.WriteLine("Done.")
Catch e As Exception
Console.WriteLine(e)
End Try
Console.ReadLine()
End Sub
' Adds an ACL entry on the specified directory for the specified account.
Sub AddDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
' Create a new DirectoryInfoobject.
Dim dInfo As New DirectoryInfo(FileName)
' Get a DirectorySecurity object that represents the
' current security settings.
Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()
' Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(New FileSystemAccessRule(Account, Rights, ControlType))
' Set the new access settings.
dInfo.SetAccessControl(dSecurity)
End Sub
' Removes an ACL entry on the specified directory for the specified account.
Sub RemoveDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
' Create a new DirectoryInfo object.
Dim dInfo As New DirectoryInfo(FileName)
' Get a DirectorySecurity object that represents the
' current security settings.
Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()
' Add the FileSystemAccessRule to the security settings.
dSecurity.RemoveAccessRule(New FileSystemAccessRule(Account, Rights, ControlType))
' Set the new access settings.
dInfo.SetAccessControl(dSecurity)
End Sub
End Module
AR
AR
|
|
|
|
|
where I can download the SAP.net Connector set up MSI to use with Visual Studio .net 2005
|
|
|
|
|
sunder vel wrote: where I can download the SAP.net Conne
What happens if you type "SAP.net" into Google?
|
|
|
|
|
I am creating a progam for a client where I have to create a application that have a forex exchange on it but the problem is I have no code to create please help!!!!
Romeo
|
|
|
|
|
I take it you're talking about the The Foreign Exchange Market??
Help with what? Don't ask us to write code for you - that's just not going to happen. Why should we break a sweat so you can take credit for it?
|
|
|
|
|
It's been a very long time since I used that stuff, but, IIRC, no there isn't. You'd have to use a third party reporting library, like CrystalReports, to do this.
|
|
|
|
|
i have a software Written in VB.Net, i want to add two Buttons, i need to Write another vb.net application from scratch, is it possible to intergrade those buttons?
Vuyiswa
|
|
|
|
|
What do you mean by 'integrate' ? You can create controls and reuse them, yes.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
i want to add the button in a form, the application is already deployed.i want to add a functionality as a button in an exsisting Application.
Vuyiswa
|
|
|
|
|
Have you got the source code to the application?
If not is the application got support for scripting with VBA or VBScript?
If you have the source code, then modify it accordingly. If not, but the app has support for VBScript then hopefully then form is exposed to scripting engine so you can add controls.
If none of the above applies then I think you are out of luck
Steve Jowett
-------------------------
Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'
|
|
|
|
|
Steven is correct. If you don't have the source code to the other app or it doesn't expose any kind of functionality to add controls, you're out of luck.
You can't add another control to a seperate application without pulling off some serious C++ and Win32-Fu. The technique is called "DLL Injection" and it can't be done using Managed Code.
|
|
|
|