|
Okay, for the sake of simplicity I will assume you have a User class in your project with public properties UserName and Password. In this class you need to create a constructor that accepts a parameter for the username and one for the password (I would hope the password is encrypted) i.e
Public Sub New(ByVal Name As String, ByVal Pass As String)
UserName = Name
Password = Pass
End Sub
You then need to create a function that saves your user i.e
Public Function SaveUser() As Integer
Dim conDB As New MySqlConnection("server=localhost;uid=sa;pwd=;database=pubs")
Dim myCon As New MySqlCommand
myCon.CommandText = "INSERT INTO Users (Username, PassWord) VALUES (@Username,@Password)"
myCon.Connection = conDB
myCon.Parameters.AddWithValue("@Username", UserName)
myCon.Parameters.AddWithValue("@Password", Password)
Dim intResult As Integer = 0
conDB.Open()
intResult = myCon.ExecuteNonQuery
conDB.Close()
Return intResult
End Function
in your Button.Click event you can just do this,
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newUser As New User(txtUserName.Text, txtPassword.Text)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newUser As New User(txtUserName.Text, txtPassword.Text)
If newUser.SaveUser() = 0 Then
MsgBox("User Not Saved")
Else
MsgBox("User Successfully Saved")
End If
End Sub
End Sub
modified on Thursday, January 21, 2010 7:04 AM
|
|
|
|
|
I'm in VS2008 and as I debug my project the memory use of devenv keeps increasing until it takes up all of my memory. This never happened in VS2005. Any ideas appreciated.
|
|
|
|
|
Does this kind of thing happen when you run the application in 'go live' mode?
Now...bring me that horizon. And really bad eggs...Drink up me hearties, YO HO!
|
|
|
|
|
|
You did buy all the memory, why are you hoping it doesn't get used?
Good software takes advantage of available memory, while being willing to give up a lot of it when requested to do so. In that sense VS2008 and Vista are good. They both object to memory holding "nothing". They keep data around like a cache.
Experiment: start two instances of Visual Studio and have them both do whatever it was you did with one VS. Each of them will be slightly slower and use less memory than the single one did.
Of course, there are also other ways to really waste memory (e.g. memory leaks), where the user is not getting any advantage. Memory wasted like that is unlikely to be recoverable (try minimizing your app and watch what TaskManager says about the working set; mind you, TaskManager is not a very good indicator).
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
OK, but I still don't see why VS2008 should not give memory back. Each time I start the solution more memory is taken by the program. Stopping the program or minimizing it does not give memory back. Eventually Task Manager shows the private working set at almost 2G. Is this really normal behavior?
ty
|
|
|
|
|
That does not sound all right. It may be a bug in VS. I'm not aware of such bug though.
You are aware Visual Studio executes some of your code (such as Form constructors) while you are designing your Forms, so any memory leaks you have in such code would accumulate.
Does the memory situation deteriorate when you run your app to completion? or only when it crashes, or you stop the execution prematurely by hitting the "Stop Debugging" menu/icon/key combination?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
What's very strange is that the memory use does not increase significantly while I'm running the program but only after I stop it. Within a few seconds after the program stops (no matter whether it breaks or finishes) the memory use goes up substantially.
|
|
|
|
|
Very strange indeed. Never seen such a phenomenon.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Dear developers,
I have problem in calling function from module in access 2007.
1. Let's see my code:
Public Function insertDB(tblName As String, tblField As String, strValue As String, db As ADODB.Database)
Dim Str As String
Dim Rst As New ADODB.Recordset
Rst.CursorLocation = adUseClient
Str = "Insert into" & tblName & "(& tblField &)" & " Values(" & strValue & ")"
db.Execute Str
End Function
Is it the correct function???
2. How to call this function in the form??
Cheers,
Visoth
Chuon Visoth
Angkor Wat - Cambodia
asp.net - c sharp beginner
|
|
|
|
|
It's close to being right...
misCafe wrote: Str = "Insert into" & tblName & "(& tblField &)" & " Values(" & strValue & ")"
Should be:
Str = "Insert into" & tblName & " (" & tblField ") Values(" & strValue ")"
Of course, this method needs a little more looking at, as you will need to ensure that your strValue parameter includes single quotes around the string you are inserting (if it's a string).
You would call this function from the form perhaps via the On Click event of a button.
|
|
|
|
|
The function does not actually return anything and therefore should be a sub rather than a functions
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Can you correct this function for me?
What's more, I do not how to write code to call this function too.
Chuon Visoth
Angkor Wat - Cambodia
asp.net - c sharp beginner
|
|
|
|
|
Hi guys,
This is my first posting on here, be gentle!
Bit of a novice really but need some help.
I'm re-doing a work's Document Repository and I need the following out of this bit of code:
- List a folder contents: Done
- Import the folder contents to an array list: Done
- Extract the Name, FullName and CreationDate only: Need Help
- Make the FullName a clickable Hyperlink: Need Help
- Export the Name, CreationDate and FullName Hyperlinks to Excel: Need Help
Thanks to you all! Keep up the good work on this site.
Cav
The code snipet so far is below:
-------------------------------------------------------------------------------------------------------
Public Class frmMain
Dim hyperarray As New ArrayList
Private m_da_Addresses As OleDbDataAdapter
Private m_DataSet As DataSet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowseOpen.Click
Dim basepath As String
Dim array As New ArrayList
' Declare a variable named theFolderBrowser of type FolderBrowserDialog.
Dim theFolderBrowser As New FolderBrowserDialog
' Set theFolderBrowser object's Description property to
' give the user instructions.
theFolderBrowser.Description = "Please select a folder for the download."
' Set theFolderBrowser object's ShowNewFolder property to false when
' the a FolderBrowserDialog is to be used only for selecting an existing folder.
theFolderBrowser.ShowNewFolderButton = False
' Optionally set the RootFolder and SelectedPath properties to
' control which folder will be selected when browsing begings
' and to make it the selected folder.
' For this example start browsing in the Desktop folder.
theFolderBrowser.RootFolder = System.Environment.SpecialFolder.Desktop
' Default theFolderBrowserDialog object's SelectedPath property to the path to the Desktop folder.
theFolderBrowser.SelectedPath = My.Computer.FileSystem.SpecialDirectories.Desktop
' If the user clicks theFolderBrowser's OK button..
If theFolderBrowser.ShowDialog = Windows.Forms.DialogResult.OK Then
' Set the FolderChoiceTextBox's Text to theFolderBrowserDialog's
' SelectedPath property.
tbOpenFolder.Text = theFolderBrowser.SelectedPath
basepath = theFolderBrowser.SelectedPath
End If
RecursiveSearch(basepath, array)
End Sub
Private Sub RecursiveSearch(ByRef basepath As String, ByRef array As ArrayList)
Dim int As Integer = 0
Dim dirInfo As New IO.DirectoryInfo(basepath)
' Try to get the files for this directory
Dim pFileInfo() As IO.FileInfo
Dim ooo As String
ooo = dirInfo.FullName
Try
pFileInfo = dirInfo.GetFiles()
Catch ex As UnauthorizedAccessException
MessageBox.Show(ex.Message, "Exception!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
' Add the file infos to the array
array.AddRange(pFileInfo)
WriteToText(array)
' Try to get the subdirectories of this one
Dim pdirInfo() As IO.DirectoryInfo
Try
pdirInfo = dirInfo.GetDirectories()
Catch ex As UnauthorizedAccessException
MessageBox.Show(ex.Message, "Exception!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
' Iterate through each directory and recurse!
Dim dirIter As IO.DirectoryInfo
For Each dirIter In pdirInfo
hyperarray.Add(dirInfo.FullName)
RecursiveSearch(dirIter.FullName, array)
Next dirIter
End Sub
Private Sub WriteToText(ByRef array As ArrayList)
dgvFiles.DataSource = array
ListBox1.DataSource = hyperarray
End Sub
-------------------------------------------------------------------------------------------------
|
|
|
|
|
cavana1 wrote: Extract the Name, FullName and CreationDate only
Look at System.IO.FileInfo
for example :-
Dim myFile as System.IO.FileInfo("C:\MyFolder\MyFile.txt")
then look at the properties of myFile
cavana1 wrote: Export the Name, CreationDate and FullName Hyperlinks to Excel
You could create an HTML file but with at extension .xls
The file should contain a table, and Excel will then read it in as an spreadsheet.
for example
<html>
<head />
<body>
<table>
<tr>
<td>File name</td>
<td>Created</td>
<td>Full Path</td>
</tr>
<!-- Add a section as follows for each file -->
<tr>
<td>MyFile.xls</td>
<td>01/01/2010 09:00:00</td>
<td><a href="File://C:\MyFolder\MyFile.txt">C:\MyFolder\MyFile.txt</a></td>
</tr>
<!-- end of section -->
</table>
</body>
</html>
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Hi Friends,
I have created one ocx file in visual basic 6.0.
It is doing some process finally it will print one text.
Is there anyway to return that text as picture so that I can capture it
from the external application.
thanks in advance..
|
|
|
|
|
|
much of thanks Estys.
I have done that ocx which is returning image. However, now I'm facing one problem. While catching the image via calling ocx methods from External application, it is return image perfectly but appearing two small dots at the edge of the image.
But this is not happening while calling the same ocx from microsoft products such vb, C# etc.
I'm suspecting it is concatenating some special character with the originall output. Microsoft products identifing that special characters, hence it is not displaying i.e, two dots with image.
Kindly clarify.
Regards,
Asan
|
|
|
|
|
No clarification possible at this stage. It's almost 15 years since I toyed with ocx'es and winApi.
- Your ocx is made with vb6?
- What is your "external application"?
- It functions ok with vb and C#?
Maybe a code snippet?
Cheers
I hate signatures but do like high ratings
|
|
|
|
|
Hello there,
I have an MS Access query that works as expected from its UI, but when invoked from vb app using OleDb.OleDbCommand it does not. This is problaby silly, but I can't get around it. Could somebody kindly offer some advice?
Here is the query def:
SELECT [Id_UCAB], Sum([Copias]) AS Cant, ([Paginas]*Sum([Copias])) AS CantPag
FROM PrintedDocs AS A, Docs AS B
WHERE A.DocId=B.DocId And (Id_UCAB Like IIf(ISNULL([@DocId]),Id_UCAB,[@DocId]) And (Fecha>=IIf(ISNULL([@FechaIni]),Fecha,[@FechaIni]) And Fecha<=IIf(ISNULL([@FechaFin]),Fecha,[@FechaFin])))
GROUP BY [Id_UCAB], [Paginas]
ORDER BY IIf([@OrdCod]=1,[Id_UCAB],([Paginas]*Sum([Copias])));
As you can see it has 4 optional parameters that are requested by Access in the following order: @DocId, @FechaIni, @FechaFin, @OrdCod.
When I invoke it from Access UI giving its first param the value: "*ABM*"; it works ok and retrieves the 3 records from table Docs where Id_UCAB like "*ABM*". So far so good.
When I invoke this query from VB.Net app using OleDb.OleDbCommand the story changes. If I ommit the value for the first param, and play around with the other 3 it works as expected, but it does not work when given the same "*ABM* value to the first param(it returns no records).
Here is the declaration of the params:
With cmd.Parameters
.Add(New OleDb.OleDbParameter("@DocId", OleDb.OleDbType.VarChar, 12, Input, 0, 0, Nothing, DataRowVersion.Current, False, Nothing))
.Add(New OleDb.OleDbParameter("@FechaIni", OleDb.OleDbType.Integer, 4, Input, 10, 0, Nothing, DataRowVersion.Current, False, Nothing))
.Add(New OleDb.OleDbParameter("@FechaFin", OleDb.OleDbType.Integer, 4, Input, 10, 0, Nothing, DataRowVersion.Current, False, Nothing))
.Add(New OleDb.OleDbParameter("@OrdCod", OleDb.OleDbType.TinyInt, 2, Input, 10, 0, Nothing, DataRowVersion.Current, False, Nothing))
End With
Here is how I assign the values before calling the Fill method of the Oledb.Oledb.DataAdapter:
With Cmd
If (DocId <> "") Then
.Parameters(0).Value = CType(DocId, String)
Else
.Parameters(0).Value = Global.System.DBNull.Value
End If
If (FechaIni <> "") Then
.Parameters(1).Value = CType(FechaIni, Integer)
Else
.Parameters(1).Value = Global.System.DBNull.Value
End If
If (FechaFIn <> "") Then
.Parameters(2).Value = CType(FechaFIn, Integer)
Else
.Parameters(2).Value = Global.System.DBNull.Value
End If
If (OrdCod <> "") Then
.Parameters(3).Value = CType(OrdCod, Byte)
Else
.Parameters(3).Value = Global.System.DBNull.Value
End If
End With
What I am missing?
Thanks for your time and help.
Best Regards.
|
|
|
|
|
Your first parameter is a string. Try enclosing it using two double quotes.
|
|
|
|
|
Hi Dragon_
I appreciate your idea, but the actual content of the variable itself is already being cast as a string; any how, since you took the time to make the suggestion, I decided to take the time to try it by forcing a set of doulbe quotes, and it did not work either.
I have even tested it from a VB6 small app I made just for this purpose and get the same result.
I am convinced it must be something so obvious that I can't pin-point-it.
Thanks any ways.
|
|
|
|
|
alexvw,
I had a almost similar encounter when I was programming with MS Access. I had a SQL query, in it was an IN (..) statement with string data types. What I did in VB was iterate each string and enclosed it with quotes. Like ab would be 'ab'. It would be "....somefield IN ('condvalue1', 'condvalue2'..) AND anotherfield=""ab"".... " But I did not use the parameter field. You can try and assigning values with quotes on the parameter field and see what the return value is. Maybe it formats the values you pass to it.
Regards,
dragon_
|
|
|
|
|
Hi there,
After some extensive online search I found the solution. Ms Access db engine uses "*" as a wild character, while ADO components do not.
If you create a query in Access using the LIKE operator, you must use the "*" character for your search to work, and if you try to create it using the SQL wild character "%" it will fail to compile.
On the other hand, if you issue a call to an Access query from a VB App through ADO using the "*" charater your LIKE operator will return nothing, but if you use the SQL wild character "%" you'll obtain a populated recordset.
So basically, the query must be:
Select a, b, c, From ThisTable
Where MyField LIKE @Param
Where @Param (from your VB App) should the proper combination of % & strvalue you require; e.g. "%strvalue" | "%strvalue%" | "strvalue%".
Thank you all.
|
|
|
|
|
Hi im here again,
i got this code that show me the name of the controls in my form
Public Sub GetControls(ByVal owner As Form)
Dim fis As System.Reflection.FieldInfo()
fis = owner.GetType().GetFields(Reflection.BindingFlags.NonPublic Or _
Reflection.BindingFlags.Instance Or _
Reflection.BindingFlags.IgnoreCase)
For Each fi As Reflection.FieldInfo In fis
If TypeOf (fi.GetValue(owner)) Is Control Then
MessageBox.Show(fi.Name)
End If
Next
End Sub
I'm trying this because i wanna put this in the load form, but i wanna make a comparation like this,
if fi.name = "101" then button.BackColor = Green something like this , how can i do?, only i wanna change the backcolor of the button with that name, only if the comparation is true
|
|
|
|
|
spawneditions wrote: if fi.name = "101" then button.BackColor = Green
if fi.name = "101" then fi.BackColor = Green
ftfy.
|
|
|
|
|