|
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.
|
|
|
|
|
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
|
|
|
|