|
Hi rahuldsac.
Bad news: Nobody's able to send VB.NET project to you, but the good news is, CERN called justed a moment ago: they discovered a new elementary particle and they want to name it after you: the Moron.
"A moron is a special kind of elementary particle. The moron is classified as massless and with a spin of "dizzying". Morons are thought to normally travel at the speed of light, though it is possible to render them inert and motionless by passing then near cold beer. In String Theory, Morons are believed to be composed of Dubliner cheese and are believed to be the messenger particle, which represents unity (one unit) of the weak force Stupid."
|
|
|
|
|
Hi every one...
I have a Windows Form Application in VB.Net... in this Windows Form I have a textBox... with a "validate" button...
I need that when I input a user ID in the text box, the application go to the access and user table to see if the user is admin... if true print user name is admin else prints user name is not admin
the 2 tables design
tblUser (IDUser, UserName, FullName)
tblAcess (IDUser, AccessLevel [that can be admin or user] )
I just try to do it, but I receaved a message that the datareader is allready open and I cannot open other datareader.... see my code please:
<br />
Private Sub txtCardNum_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCardNum.KeyPress<br />
If Char.IsNumber(e.KeyChar) Or e.KeyChar = Chr(13) Or e.KeyChar = Chr(8) Then<br />
e.Handled = False<br />
If e.KeyChar = Chr(13) Then<br />
If txtCardNum.Text = "" Then<br />
MsgBox("User ID can not be empty")<br />
Else<br />
Dim CardNum As String = txtCardNum.Text<br />
<br />
Dim SQL As String<br />
SQL = "SELECT U.CodUser, U.FullName FROM tblUser U INNER JOIN tblAccess A ON U.CodUser = A.CodUser WHERE A.AccessLevel = 'Admin' AND A.CodUser = @CodUser"<br />
Dim myCommand = New SqlCommand(SQL, myConnection)<br />
myCommand.Parameters.Add("@CodUser", SqlDbType.VarChar).Value = CardNum<br />
<br />
Dim SQL2 As String<br />
SQL2 = "SELECT CodUser, FullName FROM tblUser WHERE CodUser = @CodUser"<br />
Dim myCommand2 = New SqlCommand(SQL2, myConnection)<br />
myCommand2.Parameters.Add("@CodUser", SqlDbType.VarChar).Value = CardNum<br />
<br />
Dim reader As SqlDataReader = myCommand.ExecuteReader()<br />
Dim reader2 As SqlDataReader = myCommand2.ExecuteReader()<br />
'Caso existam linhas<br />
If reader.HasRows Then<br />
While reader.Read()<br />
lblFullName.Text = reader(1)<br />
lblLevel.Text = "Admin" <br />
txtCardNum.Text = "" <br />
End While<br />
reader.Close()<br />
Else<br />
Dim reader2 As SqlDataReader = myCommand2.ExecuteReader()<br />
lblNomeCliente.Text = reader2(1)<br />
lblLevel.Text = "Normal User"<br />
txtCardNum.Text = ""<br />
reader2.Close()<br />
End If<br />
End If<br />
End If<br />
Else<br />
e.Handled = True<br />
End If<br />
<br />
End Sub<br />
<br />
but when I try to execute and do the query I receave a error: "the data reader is allready open"
how can I solve it?
thanks
regards
PS
|
|
|
|
|
This was a pretty obvious error. You already open two readers, then you try and execute the second reader again. You have this line in your code twice:
Dim reader2 As SqlDataReader = myCommand2.ExecuteReader()
Remove the second occurance and you should be fine.
|
|
|
|
|
Hi!
Thanks for your reply...
I forgote to say something... When I execute this, if the user is Admin, it will be fine and I will see the user fullname, but if the user are not a admin, I cant continue...
I remove this line
Dim reader2 As SqlDataReader = myCommand2.ExecuteReader()
now I see this error: trying to read a unvaible data or somethig like this
System.InvalidOperationException was unhandled
Message="Tentativa de leitura inválida quando não estão presentes dados."
Source="System.Data"
StackTrace:
em System.Data.SqlClient.SqlDataReader.GetValue(Int32 i)
em System.Data.SqlClient.SqlDataReader.get_Item(Int32 i)
em SiSGym_Monitor.MainForm.txtCardNum_KeyPress(Object sender, KeyPressEventArgs e) em C:\Desenvolvimento\SiSGym Monitor\SiSGym Monitor\MainForm.vb:line 234
em System.Windows.Forms.Control.OnKeyPress(KeyPressEventArgs e)
em System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
em System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
em System.Windows.Forms.Control.WmKeyChar(Message& m)
em System.Windows.Forms.Control.WndProc(Message& m)
em System.Windows.Forms.TextBoxBase.WndProc(Message& m)
em System.Windows.Forms.TextBox.WndProc(Message& m)
em System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
em System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
em System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
em System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
em System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
em System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
em System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
em System.Windows.Forms.Application.Run(ApplicationContext context)
em Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
em Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
em Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
em SiSGym_Monitor.My.MyApplication.Main(String[] Args) em 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
em System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
em System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
em System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
em System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
em System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
em System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
em System.Activator.CreateInstance(ActivationContext activationContext)
em Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
em System.Threading.ThreadHelper.ThreadStart_Context(Object state)
em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
em System.Threading.ThreadHelper.ThreadStart()
InnerException:
|
|
|
|
|
That error message says (through Google Translate) that you're trying retrieve a value that doesn't exist, or the record doesn't exist. Your code appears to be assuming that the SQL query returns records, when in fact, nothing gets returned. You don't chack this and just start retrieving values from a record that doesn't exist.
|
|
|
|
|
Hi
my problem is:
Hi have two tables (One with user info and other with level access [admin and regular user] )
How can I do a sql query in vb.net that can do that...
- Check if the user exists... then check if is admin:
-- If this statement is true, then print User FullName in lblFullName and YOU IS ADMIN in lblLevelAccess
Else
print user Fullname in lblFullName and YOU ARE NOT ADMIN in lblLevelAccess...
How can do it in vb.net
thanks for your help
|
|
|
|
|
Patrício dos Santos wrote: How can I do a sql query in vb.net that can do that...
- Check if the user exists... then check if is admin:
-- If this statement is true, then print User FullName in lblFullName and YOU IS ADMIN in lblLevelAccess
Else
By breaking the problem down into smaller and smaller parts...
Step 1:
Does the user exist?
Step 2:
If so, retrieve the account details.
Your code has these two steps globbed together into one monolithic method that really should be broken down into more methods that do very specific things.
I already told you what the problem is. You're not checking to see if your second reader actually returned any records. You're just assuming it did.
|
|
|
|
|
Step 1: Yes, we assume that the user exist.
step 2: I can execute this part of code...
Dim SQL As String<br />
SQL = "SELECT U.CodUser, U.FullName FROM tblUser U INNER JOIN tblAccess A ON U.CodUser = A.CodUser WHERE A.AccessLevel = 'Admin' AND A.CodUser = @CodUser"<br />
Dim myCommand = New SqlCommand(SQL, myConnection)<br />
myCommand.Parameters.Add("@CodUser", SqlDbType.VarChar).Value = CardNum<br />
<br />
Dim reader As SqlDataReader = myCommand.ExecuteReader()<br />
Dim reader2 As SqlDataReader = myCommand2.ExecuteReader()<br />
'Caso existam linhas<br />
If reader.HasRows Then<br />
While reader.Read()<br />
lblFullName.Text = reader(1)<br />
lblLevel.Text = "Admin"<br />
txtCardNum.Text = ""<br />
End While<br />
reader.Close()<br />
<br />
...<br />
if the user exists and is admin, I can print their full name, but is not admin but exists, I cannot do it
Else<br />
lblNomeCliente.Text = reader(1)<br />
lblLevel.Text = "Normal User"<br />
txtCardNum.Text = ""<br />
reader.Close()<br />
End If
I receave always the error that the datareader is closed, but if I close it (reader.close() ) I receave other error that there no data or something like this
PS: sorry my english, I am angolan
thanks
|
|
|
|
|
OK, I'll say this again. Your code is one monolithic glob that should be broken down into smaller parts, doing very specific things.
For instance, your top example executes two readers at the same time, but you haven't even checked to see if the user exists yet! Why execute the second record if you don't need it?? Execute the first query, check to see if you get ONE record back. If you don't, you need to handle those cases. If you get one record, do whatever you need to do with the data you have, then execute the second query and check to see if you get back more or less than one record. yada, yada, yada, ...
Patrício dos Santos wrote: PS: sorry my english, I am angolan
It's not your English that's the problem. It's the logic and the breaking down of the problem that's the problem.
|
|
|
|
|
Hi All,
I am having an issue at work where the .dat (fixed length) file generated for import into a client application (generated and e-mailed to customers in vb.net code using smtpclient) is being compressed into a .zip file. This is causing an issue at customer stores as they are unable to open the files and import. Any ideas why it is doing this? Is it outlook? Is it my vb application (unlikely because if you access the shared folder containing the file before sending it is not compressed) or is it the server? I really need to ghet this fixed as the phone is ringing off the hook and I cant find any helpful articles anywhere.
thanks guys,
|
|
|
|
|
I think it will be your outlook.
There are various options somewhere. There are also ones that resize images if you attach pictures.
|
|
|
|
|
Na, It's something on the server. We used another mail smtp client and it worked fine. So now where to look on the server is the question?
|
|
|
|
|
Your comment doesn't make sense.
Mr Oizo wrote: We used another mail smtp client and it worked fine
Mr Oizo wrote: It's something on the server
So in your original Post, you questioned if it was something to do with Outlook? you now say it works fine with another SMTP client, so blame the server?
|
|
|
|
|
Hi, Sorry, perhaps I am saying the wrong thing, I am not too familiar with e-mail sever lingo. Basically we used a different mail server to send it off (which i specify as a new smtp client I.p address) and then it did not compress the file. It sends through code to pc's using outlook. But when using the first smtp client I.p (server1) address it zipped the file. On the second I.p (server 2) it didn't. Thats why I can only assume something on the first mail sever is compressing the files when sending
|
|
|
|
|
That makes more sense now. You used a different email server and now it works.
Well then, you will need to find out the type of server, and look up the documentation to find out if there are options to turn off automatic compression of attachments.
There may also be a custom parameter value that you can pass in with the message from the client, to turn this on/off on a message by message basis, but you will need to go and investigate, as i have no idea what type of mail server you are using!
|
|
|
|
|
Thanks,
I'll take a look and see if I can find anything. Unfortuanately the mail server is administered by a different company but I mainly wanted to establish that it was not something on my side, rather something with their server.
Thanks for the help.
|
|
|
|
|
Hi,
I like to know to split a string value from a mixed value
suppose
dim MyValue as string ="CodePr1"
Now I need to seperate the string part like "CodePr"
Is there any short ideas?
Thanks
|
|
|
|
|
I just did this off the top of my head. I don't know if there is a .net function for this.
Private Function SplitStringAtFirstNumeral(ByVal mystring As String) As String()
Dim myArray(1) As String
Dim i As Integer = 0
For Each ch As Char In mystring
If IsNumeric(ch) Then
myArray(0) = mystring.Substring(0, i)
myArray(1) = mystring.Substring(i, mystring.Length - i)
Exit For
End If
i += 1
Next
Return myArray
End Function
If anyone has a better way please let me know.
|
|
|
|
|
I did the same way which one you gave. But looking for DotNet any direct commands.
|
|
|
|
|
Take a look here[^] for all the possibilities with the String class; you may need to use more than one method to achieve the desired result.
MVP 2010 - are they mad?
|
|
|
|
|
I wanna know how to insert both username and password into my database using the vb.net
I just wanted to create a "Create An Acount" form
whereby the button can actually insert the username and the password into my database
any1 can guide me on this?
Thanks,
|
|
|
|
|
To communicate with any database with vb.net requires the use of ADO.net. To communicate with a MySQl database requires the use of the MySql
connector/net which can be found here http://www.mysql.com/products/connector/[^]. To insert records into your database will require the use of SQL. I suggest you read this article ADO.NET For Beginners[^] and then buy any decent beginners VB.net book which should teach you these three fundamental principles. If you have started an approach to this problem and are stuck with a specific programming question then I will be more than willing to help further.
|
|
|
|
|
i need some help with this source code that i have,
ok wat i wan is when i click on the button on the form it can help me create a new account and both the username and the password will be store in the database.
Imports
System.Data.SqlClient
Public Class Form2 Inherits System.Windows.Forms.Form
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim ra as Integer
'integer holds the number of records inserted
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles Button1.Click
myConnection = New SqlConnection("server=localhost;uid=sa;pwd=;database=pubs")
'you need to provide password for sql server
myConnection.Open()
myCommand = New SqlCommand("Insert into Jobs values 12,'IT Manager',100,300,_
myConnection)
ra=myCommand.ExecuteNonQuery()
MessageBox.Show("New Row Inserted" & ra)
myConnection.Close()
End Sub
End Class
|
|
|
|
|
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.
|
|
|
|
|