|
|
Cool anwser..It may be boosting saravanan
Regards,
Sylvester G
sylvester_g_m@yahoo.com
|
|
|
|
|
|
hi
i got the answer thanks lot satips and sylvester
regards
saravana
|
|
|
|
|
hi
i wrote another simple function
Public Sub cookies()
If Not IsPostBack Then
If Not Request.Cookies("UserInfo") Is Nothing Then
Dim username As String
Dim password As String
Dim checkbox As String
txtusername.Text = Decrypt(Request.Cookies("UserInfo")("UserName").ToString())
txtpassword.Attributes.Add("value", (Decrypt(Request.Cookies("UserInfo")("Password").ToString())))
End If
End If
End Sub
Public Shared Function Encrypt(ByVal Data As String) As String
Dim shaM As New SHA1Managed
Convert.ToBase64String(shaM.ComputeHash(Encoding.ASCII.GetBytes(Data)))
Dim eNC_data() As Byte = ASCIIEncoding.ASCII.GetBytes(Data)
Dim eNC_str As String = Convert.ToBase64String(eNC_data)
Encrypt = eNC_str
End Function
Public Shared Function Decrypt(ByVal Data As String) As String
Dim dEC_data() As Byte = Convert.FromBase64String(Data)
Dim dEC_Str As String = ASCIIEncoding.ASCII.GetString(dEC_data)
Decrypt = dEC_Str
End Function
Private Sub butuser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butuser.Click
Dim username As String
Dim password As String
Dim checkbox As String
username = txtusername.Text
password = txtpassword.Text
If username <> "" Then
'if Username is not null
username = Encrypt(username)
'encrypting the password to salt 8 algorithm
username = username.Replace("'", "''")
End If
If password <> "" Then
password = Encrypt(password)
'encrypting the password to salt 8 algorithm
password = password.Replace("'", "''")
End If
If (chkplayer.Checked = True) Then
Dim objCookie As New HttpCookie("UserInfo")
objCookie.Values.Add("UserName", username)
objCookie.Values.Add("Password", password)
objCookie.Expires = DateTime.Now.AddDays(1)
'this is for one day
Response.Cookies.Clear()
Response.Cookies.Add(objCookie)
End If
Dim conn As SqlConnection = New SqlConnection("server=Wafes10;database=lgateway;uid=;pwd=;Trusted_connection=true")
conn.Open()
Dim cmd As SqlCommand = New SqlCommand("select count (*) from register where uname='" + txtusername.Text + "' and password='" + txtpassword.Text + "'", conn)
Dim dr As SqlDataReader
dr = cmd.ExecuteReader
dr.Read()
Dim rowcount As String
rowcount = dr(0).ToString
dr.Close()
If rowcount = 1 Then
'cookies()
thanks lot
regards
saravanan
|
|
|
|
|
Hi, I am new to ASP.NET and VB.NET. My app is supposed to check if a user already exists. On one of the lines of code below I'm trying to use CType to retrieve a data from the database. I get the error message "Object reference not set to an instance of an object". I did a search on this error message and found one site that saia that the most common cause of this is that one for gets to declare a variable. The second most common cause is bad scoping (declaring the variable locally instead of globally). I've checked but I did not find the above to be the cause of the error message. Perhaps you could help me spot the cause of the error message. It's most likely that I am using the CType and ExecuteScalar methods incorrectly. The following is my code, please take a look. Thank you in advance for your help.
Private Sub lblRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblRegister.Click
Dim bResult As Boolean = False
Dim myConnection As OdbcConnection
Dim myCommand As OdbcCommand
Dim strInsert As String
Dim strGoodPassword As String
Dim cmdInsert As New OdbcCommand
Dim strSQL As String
myConnection = New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=myDb;User=myUSER;Password=myPW;Option=3;")
strSQL = String.Format("SELECT myUserName FROM myTable WHERE (email='{0}');", txtUserName)
myCommand.CommandText = strSQL
myCommand.CommandType = CommandType.Text
strInsert = "INSERT into membersinfotbl (FirstName,LastName,Password,Phone,Email,Profession,StrAddress,City,State,ZipCode)value (?,?,?,?,?,?,?,?,?,?)"
myCommand = New OdbcCommand("StrInsert", myConnection)
myCommand.Parameters.Add("@FirstName", txtFirst.Text)
myCommand.Parameters.Add("@LastName", txtLast.Text)
myCommand.Parameters.Add("@Password", txtPassword.Text)
myCommand.Parameters.Add("@Phone", txtPhone.Text)
myCommand.Parameters.Add("@Email", txtEmail.Text)
myCommand.Parameters.Add("@Profession", txtProfession.Text)
myCommand.Parameters.Add("@StrAddress", txtAddress.Text)
myCommand.Parameters.Add("@City", txtCity.Text)
myCommand.Parameters.Add("@State", txtState.Text)
myCommand.Parameters.Add("@ZipCode", txtZipCode.Text)
myConnection.Open()
strGoodPassword = CType(myCommand.ExecuteScalar, String)
myCommand.ExecuteNonQuery()
If Not strGoodPassword Is Nothing Then
If strGoodPassword = txtPassword.Text Then
bResult = True
Else
lblMessage.Text = "That user name is already taken!"
lblMessage.Text &= " Please choose another user name."
End If
Else
lblMessage.Text = "That user name is already taken!"
lblMessage.Text &= " Please choose another user name."
End If
myConnection.Close()
End Sub
-- modified at 0:19 Thursday 14th June, 2007
|
|
|
|
|
ASPnoob wrote: I get the error message "Object reference not set to an instance of an object"
Which line of the code is show this error message?
|
|
|
|
|
The error is on the line below. Thank you so much for your help.
strGoodPassword = CType(myCommand.ExecuteScalar, String)
|
|
|
|
|
Hey Friend,
You are using ExecuteScalar, which is used when the Command return a value (single column value) after the execution of the SQL statement. The SQL would be SELECT statement. But here you are INSERT-ing the record into the DB. This SQL won't return you the value. (i.e) This statement return you NULL.
In simple, you are doing a wrong action, using wrong query.
|
|
|
|
|
I did use the select statement and it's used for checking if a username already exists. The select statement was used on the following line.
strSQL = String.Format("SELECT myUserName FROM myTable WHERE (email='{0}');", txtUserName).
Once it is determined a username is not already in existence, the username supplied by the user is sent to the database. I would like more detailed comments on my code, please take a good look to help me find the error. Thank you in advance for your help.
-- modified at 1:20 Thursday 14th June, 2007
|
|
|
|
|
ASPnoob wrote: strSQL = String.Format("SELECT myUserName FROM myTable WHERE (email='{0}');", txtUserName)
myCommand.CommandText = strSQL
myCommand.CommandType = CommandType.Text
You have assigned the query, but not executed the myCommand. Again you started assigning the INSERT statement. First time you have assigned the SELECT statement. You should execute the ExecuteScalar next to it and do your conditional check there. If everything ok, then assign the INSERT statement to myCommand object and execute the ExecuteNonQuery command.
Private Sub lblRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblRegister.Click
Dim bResult As Boolean = False
Dim myConnection As OdbcConnection
Dim myCommand As New OdbcCommand
Dim strInsert As String
Dim strGoodPassword As String
Dim cmdInsert As New OdbcCommand
Dim strSQL As String
myConnection = New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=myDb;User=myUSERassword=myPW;Option=3;")
strSQL = String.Format("SELECT myUserName FROM myTable WHERE (email='{0}');", txtUserName)
myConnection.Open()
myCommand.Connection = myConnection
myCommand.CommandText = strSQL
myCommand.CommandType = CommandType.Text
strGoodPassword = CType(myCommand.ExecuteScalar, String)
If Not strGoodPassword Is Nothing Then
If strGoodPassword = txtPassword.Text Then
bResult = True
Else
lblMessage.Text = "That user name is already taken!"
lblMessage.Text &= " Please choose another user name."
End If
Else
lblMessage.Text = "That user name is already taken!"
lblMessage.Text &= " Please choose another user name."
End If
strInsert = "INSERT into membersinfotbl (FirstName,LastName,Password,Phone,Email,Profession,StrAddress,City,State,ZipCode)value (?,?,?,?,?,?,?,?,?,?)"
myCommand.CommandText = strInsert
myCommand.CommandType = CommandType.StoredProcedure
myCommand.Parameters.Add("@FirstName", txtFirst.Text)
myCommand.Parameters.Add("@LastName", txtLast.Text)
myCommand.Parameters.Add("@Password", txtPassword.Text)
myCommand.Parameters.Add("@Phone", txtPhone.Text)
myCommand.Parameters.Add("@Email", txtEmail.Text)
myCommand.Parameters.Add("@Profession", txtProfession.Text)
myCommand.Parameters.Add("@StrAddress", txtAddress.Text)
myCommand.Parameters.Add("@City", txtCity.Text)
myCommand.Parameters.Add("@State", txtState.Text)
myCommand.Parameters.Add("@ZipCode", txtZipCode.Text)
myCommand.ExecuteNonQuery()
myConnection.Close()
End Sub
Try the above code....
ASPnoob wrote: strGoodPassword = CType(myCommand.ExecuteScalar, String)
ASPnoob wrote:
If Not strGoodPassword Is Nothing Then
If strGoodPassword = txtPassword.Text Then
bResult = True
Else
lblMessage.Text = "That user name is already taken!"
lblMessage.Text &= " Please choose another user name."
End If
Else
lblMessage.Text = "That user name is already taken!"
lblMessage.Text &= " Please choose another user name."
End If
But I am confused, why you are validating the Password with the Username field.
|
|
|
|
|
Thank you for responding to my question. You were right to be confused about my use of the Password to validate Username field. It was a typo I meant to use txtUserName.text instead of txtPassword.text. I still did not solve the original problem and that is the error message "Object reference not set to an instance of an object". The line thats causing the error message is "myCommand.CommandText = strSQL". I don't know what else to do but I'll keep on looking for the answer. Thanks again for your time.
|
|
|
|
|
ASPnoob wrote: strSQL = String.Format("SELECT myUserName FROM myTable WHERE (email='{0}');", txtUserName)
If txtUserName is a TextBox, use as txtUserName.Text in the SELECT statement
|
|
|
|
|
Thanks for helping, I've changed the select statement like you've suggested. However, I still get the same exact error message as before. I did a search on the error message, and I read that it could be caused by not initializing the variable strSQL I'm using in my code. So I initialized it with the following
"strSQL=String.Empty"
I get the same exact error message at the same line, please help me solve this problem. Thank you for your time.
-- modified at 3:24 Thursday 14th June, 2007
|
|
|
|
|
Hi,
According to my observation of your code you have not assigned a new instance to your myCommand object of OdbcCommand.
You just have written
Dim myCommand As OdbcCommand
You should write Dim myCommand As New OdbcCommand
or following line you should instert before doing any operation with myCommand
myCommand = New OdbcCommand()
You have done this with cmdInsert but not with myCommand.
I hope this will solve your problem.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
hi, i have put up a post before abt my project. i am able to run my project but now i ahve a problem because all my code is in .aspx now i need to put the code into aspx.vb i try to double click the submit button but it brings me to .aspx n there is a i would want to know how to transfer my code into the aspx.vb below is my code in .aspx thanks a lot in advance.
<script runat="server">
Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Moviename
Dim Actorname
Dim Director
Dim Language
Dim Numberofdisc
Dim Studio
Dim ReleaseDate
Dim Price
Dim Quantity
Dim sql
'Dim asql
Dim DBconn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("dvd_rental.mdb"))
DBconn.Open()
Moviename = Request.Form("txtmovieName")
Actorname = Request.Form("txtActorname")
Director = Request.Form("txtDirector")
Language = Request.Form("txtLanguage")
Numberofdisc = Request.Form("txtNoofdisc")
Studio = Request.Form("txtStudio")
ReleaseDate = Request.Form("txtReleaseDate")
Price = Request.Form("txtPrice")
Quantity = Request.Form("txtQuantity")
sql = "INSERT INTO Movie(MovieName, MovieLanguage, Numberofdisc, Studio, ReleaseDate, Price, Quantity) "
sql = sql & "VALUES('" & Moviename & "'"
sql = sql & ",'" & Language & "'"
sql = sql & ",'" & Numberofdisc & "'"
sql = sql & ",'" & Studio & "'"
sql = sql & ",'" & ReleaseDate & "'"
sql = sql & ",'" & Price & "'"
sql = sql & ",'" & Quantity & "')"
'asql = "INSERT INTO Actor(Actor Name)VALUES('" & Actorname & "')"
'Dim dbq As New OleDb.OleDbCommand
'dbq.CommandType = CommandType.Text
'dbq.CommandText = asql
'dbq.Connection = DBconn
'dbq.ExecuteNonQuery()
Dim dbquery As New OleDb.OleDbCommand
dbquery.CommandType = CommandType.Text
dbquery.CommandText = sql
dbquery.Connection = DBconn
dbquery.ExecuteNonQuery()
DBconn.Close()
DBconn = Nothing
End Sub
<title>WebAdd.aspx
function Table1_onclick() {
}
function Text1_onclick() {
}
<asp:label id="AddNewDvd" runat="server" width="240px" designtimedragdrop="8" font-bold="True" font-size="14pt" font-names="Times New Roman">Add new DVD Record | | | |
<asp:label id="Moviename" runat="server" width="112px" font-size="14pt">DVD Title: |
<asp:textbox id="txtmovieName" runat="server"> |
<asp:label id="Actor" runat="server" width="112px" font-size="14pt">Actor: |
<asp:dropdownlist id="DropDownList1" runat="server" width="132px" enabletheming="True">
<asp:listitem>
<asp:button id="btnAddNew" runat="server" text="Add New">
<asp:textbox id="txtActorname" runat="server">
<asp:button id="btnAdd" runat="server" text="Add" width="72px">
<asp:listbox id="ListBox1" runat="server" height="94px" width="166px">
<asp:button id="btnDelete" runat="server" text="Delete">
|
<asp:label id="Director" runat="server" width="112px" font-size="14pt">Director: |
<asp:dropdownlist id="DropDownList2" runat="server" width="138px">
<asp:button id="btnAddNewD" runat="server" text="Add New">
<asp:textbox id="txtDirector" runat="server">
<asp:button id="btnAddD" runat="server" text="Add">
<asp:listbox id="ListBox2" runat="server" height="102px" width="168px">
<asp:button id="btnDeleteD" runat="server" text="Delete">
| <asp:label id="language" runat="server" font-size="14pt" width="112px">Language: | <asp:textbox id="txtlanguage" runat="server"> | <asp:label id="Numberofdisc" runat="server" font-size="14pt" width="145px">Number of Disc: | <asp:textbox id="txtNoofDisc" runat="server"> |
<asp:label id="Studio" runat="server" width="112px" font-size="14pt">Studio: |
<asp:textbox id="txtStudio" runat="server"> | <asp:label id="ReleaseDate" runat="server" font-size="14pt" width="112px">Release Date: | <asp:calendar id="Calendar1" runat="server">
|
<asp:label id="Price" runat="server" width="112px" font-size="14pt">Price: |
<asp:textbox id="txtPrice" runat="server"> |
<asp:label id="Quantity" runat="server" width="112px" font-size="14pt">Quantity: |
<asp:textbox id="txtQuantity" runat="server"> | | |
<asp:button id="Submit" runat="server" text="Submit"> | |
ling
|
|
|
|
|
Add the CodeFile = "YourFile.aspx.vb" in the @Page directive. Now copy your code into the YourFile.aspx.vb file.
|
|
|
|
|
Add a new Item selecting "place code in seperate file" and then copy the whole HTML tag part in to the aspx file, double click the button and their place the script part.
Mohan Kumar
|
|
|
|
|
Hello!
I have a websote that uses Adobe pro to view pdf documents. But now when I move it into my production enviroment, I get this error.
"Cannot create ActiveX component".
I'm guessing it's the adobe ActiveX, just not sure which one, or how should I install on the web server, or does it have to go on the client?
TIA!
Rudy
|
|
|
|
|
rudemusik wrote: I have a websote that uses Adobe pro to view pdf documents.
Are you viewing PDF or creating PDF??
|
|
|
|
|
Hi,
I am having problem with this dynamic table creation with textbox and button in it.
Firstly let me explain why I need to create table dynamically. There will be cases sending in by the user compalaining some problem with the product, then internally the manager will assign this cases to the people under him/her. Before assigning it, the manager will type in some task that advise the employee what to do with this case. There can be one, two, three to infinity tasks to be added depend on the manager's preference.
So whenever the manager click 'Add Task', one row of textbox and button will be created (btw, the button is to delete the task if the manager don't wants it), if he/she clicks again, another row will be added.
The problem is I save all this dynamic table rows in a session so that it won't go away if any postback or refresh happens. It works well untill I need to open another case, the other case will read whether there is a session and use the session, but too bad the session belongs to the previous case.
I'd tried putting the selected case id into a session, so it will remove the task session when the case id selected is different from the session id. This works well until I need to add more task to the present ones.
I'm getting very confuse on the best way to do it as my codes are getting very messy. I would like to seek for some expert advise on the right way to deal with this dynamic table.
Thanks in advance.
J Liang
|
|
|
|
|
Use a hashtable keyed with the case ID
only two letters away from being an asset
|
|
|
|
|
If I have an image field in my gridview is there a way to tie it to a link so that it is clickable?
I know there is the imagebutton column, but I don't see a way of populating the image from the database like I am doing with the image column.
For example, I have a database with a column called "image" which has the relative path on my webserver to the image. Right now I am just binding the image column to the path for its imageurl field and I get the correct image to show. The problem is that I see no way of making it a link so that people can click on it. Alternately, I see no way of binding the imagebutton field to the database "image" column. Maybe I am just overlooking it?
|
|
|
|
|
Use a template column and wrap the image in a hyperlink control.
only two letters away from being an asset
|
|
|
|
|
I see the option to add a TemplateField, but I am not sure how to do the wrapping.
|
|
|
|
|