shlvy Posted December 4, 2003 Posted December 4, 2003 Hi I have a register page that check if the user is already exist, if not the user is insert into the database. I use 2 subs that are working fine in seperate ( I took them from a book, the problem is that when i register with a username that is already exist i dont get the message inspite of that the user is not insert into the database, the subs are : 1.InsertData() , inserts the data into the table. 2.CheckUser(), checks if the user is already exist. 3.StartMe(), the submit button. I tried many things but without any succesfull, the subs are : sub StartMe(obj As Object, e As EventArgs) CheckUser() InsertData() end sub ' declare connection dim Conn as new OleDbConnection("Provider=" & "Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=C:\Inetpub\wwwroot\DataSource\R.mdb") sub InsertData() dim objCmd as OleDbCommand = new OleDbCommand ("InsertUser", Conn) objCmd.CommandType = CommandType.StoredProcedure dim objParam as OleDbParameter objParam = ObjCmd.Parameters.Add("@UserName", OleDbType.BSTR) objParam.Direction = ParameterDirection.Input objParam.Value = tbUserName.Text objParam = ObjCmd.Parameters.Add("@Password", OleDbType.BSTR) objParam.Direction = ParameterDirection.Input objParam.Value = tbPassword.Text objParam = ObjCmd.Parameters.Add("@RetypePassword", OleDbType.BSTR) objParam.Direction = ParameterDirection.Input objParam.Value = tbRetypePassword.Text objParam = ObjCmd.Parameters.Add("@Email", OleDbType.BSTR) objParam.Direction = ParameterDirection.Input objParam.Value = tbEmail.Text objParam = ObjCmd.Parameters.Add("@Comments", OleDbType.BSTR) objParam.Direction = ParameterDirection.Input objParam.Value = tbComments.Text try objCmd.Connection.Open() objCmd.ExecuteNonQuery Catch ex as OleDbException lblMessage.Text = ex.Message end try objCmd.Connection.Close() response.redirect("forferaregister.aspx") end sub sub CheckUser() dim intId as integer = 0 dim Conn1 as new OleDbConnection("Provider=" & "Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=C:\Inetpub\wwwroot\DataSource\R.mdb") dim objCmd1 as OleDbCommand = new OleDbCommand ("spValidateUser", Conn1) objCmd1.CommandType = CommandType.StoredProcedure dim objParam1 as OleDbParameter objParam1 = ObjCmd1.Parameters.Add("@UserName", OleDbType.BSTR) objParam1.Value = tbUserName.Text try objCmd1.Connection.Open() intID = CType(objCmd1.ExecuteScalar, Integer) objCmd1.Connection.Close Catch ex as OleDbException lblMessage.Text = ex.Message end try if intID <> 0 then lblMessage.Text = "Choose another UserName" else lblMessage.Text = "Hello" end if end sub I hope that i finally will end thats problem. Thank's. Quote
Administrators PlausiblyDamp Posted December 4, 2003 Administrators Posted December 4, 2003 You are calling the CheckUser sub which is checking if the user already exists or not but then calling the InsertData sub anyway - even if the user already exists. You may want to change the CheckUser to a function that returns a boolean Function CheckUser() as boolean 'Your code here 'change the end to if intID <> 0 then lblMessage.Text = "Choose another UserName" return True else lblMessage.Text = "Hello" return False end if and in the calling routine do sub StartMe(obj As Object, e As EventArgs) if CheckUser() = false then InsertData() end if end sub Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.