944,193 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 2642
  • C# RSS
Dec 6th, 2007
0

how to update profile of login member

Expand Post »
hi jerry thanks for dropdownlist, but i got another problem regarding updatating a profile of a login member, i created a storedprocedure for login information just look at my codding

(Toggle Plain Text)
CREATE PROCEDURE sp_UserValidation
(
@Username varchar(50),
@UserPassword varchar(20)
)
AS
IF EXISTS (SELECT UserName FROM LogIn1 WHERE UserName=@Username and UserPassword=@UserPassword)
BEGIN
return 1
END
ELSE
BEGIN
return 0
END
create table login1(username varchar(50)constraint pkusername primary key,userpassword varchar(20) ,
youranswer varchar(40),username varchar(20), useraddress varchar(100),usercity varchar(20),userpostal int,
userphone int,usermobile int,Email varchar(30),website varchar(30))CREATE PROCEDURE sp_UserValidation
(
@Username varchar(50),
@UserPassword varchar(20)
)
AS
IF EXISTS (SELECT UserName FROM LogIn1 WHERE UserName=@Username and UserPassword=@UserPassword)
BEGIN
return 1
END
ELSE
BEGIN
return 0
END
create table login1(username varchar(50)constraint pkusername primary key,userpassword varchar(20) ,
youranswer varchar(40),username varchar(20), useraddress varchar(100),usercity varchar(20),userpostal int,
userphone int,usermobile int,Email varchar(30),website varchar(30))
my problem is i want to update some of login member column but iam not able to update, i wrote some coding for that just go through that,

(Toggle Plain Text)
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("user id=sa;password=vubrain;database=raghu;data source=vubrain4");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "Update login1001 Set name = @username1001, pwd = @userpassword1001 where username1001= @username1001";
cmd.CommandType = CommandType.Text;
SqlParameter para2;
SqlParameter para3;
SqlParameter para4;
SqlParameter para5;
//SqlParameter para6;
SqlParameter para7;
SqlParameter para8;
SqlParameter para9;
para2 = cmd.@Parameters.AddWithValue("loginaddress", tb1.Text);
para3 = cmd.@Parameters.AddWithValue("logincity", t6.Text);
para4 = cmd.@Parameters.AddWithValue("loginpostalcode", t7.Text);
para5 = cmd.@Parameters.AddWithValue("loginphone", t8.Text);
//para6 = cmd.Parameters.AddWithValue("loginfax", t9.Text);
para7 = cmd.@Parameters.AddWithValue("loginmobile", t10.Text);
para8 = cmd.@Parameters.AddWithValue("loginemail", t11.Text);
para9 = cmd.@Parameters.AddWithValue("loginwebsite", t12.Text);
int intnum;
con.Open();
intnum = cmd.ExecuteNonQuery();
if (intnum > 0)
{
Label2.Text = "updated successfully";

}
else
{
Label2.Text = "updarted failed";
}
con.Close(); protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("user id=sa;password=vubrain;database=raghu;data source=vubrain4");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "Update login1001 Set name = @username1001, pwd = @userpassword1001 where username1001= @username1001";
cmd.CommandType = CommandType.Text;
SqlParameter para2;
SqlParameter para3;
SqlParameter para4;
SqlParameter para5;
//SqlParameter para6;
SqlParameter para7;
SqlParameter para8;
SqlParameter para9;
para2 = cmd.@Parameters.AddWithValue("loginaddress", tb1.Text);
para3 = cmd.@Parameters.AddWithValue("logincity", t6.Text);
para4 = cmd.@Parameters.AddWithValue("loginpostalcode", t7.Text);
para5 = cmd.@Parameters.AddWithValue("loginphone", t8.Text);
//para6 = cmd.Parameters.AddWithValue("loginfax", t9.Text);
para7 = cmd.@Parameters.AddWithValue("loginmobile", t10.Text);
para8 = cmd.@Parameters.AddWithValue("loginemail", t11.Text);
para9 = cmd.@Parameters.AddWithValue("loginwebsite", t12.Text);
int intnum;
con.Open();
intnum = cmd.ExecuteNonQuery();
if (intnum > 0)
{
Label2.Text = "updated successfully";

}
else
{
Label2.Text = "updarted failed";
}
con.Close();
please sought out my problem
thank you
raghu
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
raghu.8 is offline Offline
40 posts
since Nov 2007
Dec 9th, 2007
0

Re: how to update profile of login member

raghu,

That SQL statement should have thrown some errors.
I assume you are using Microsoft SQL.
First off, it is typically not a good idea to use commandtext. Instead use stored procedures whenever possible.
Although you are adding parameters to the CMD, because the CMD type is CommandText those parameters
are not going anywhere. Also, you need to format the CommentText properly. Example:
C# Syntax (Toggle Plain Text)
  1. cmd.CommandText = "Update login1001 Set name = @username1001, pwd = @userpassword1001 where username1001= @username1001";
  2. cmd.CommandType = CommandType.Text;

should be rewritten as such:
C# Syntax (Toggle Plain Text)
  1. string m_username = "Whatever this user name is";
  2. string m_pswd = "whatever the password is";
  3. SqlConnection con ... all that jaz...
  4. cmd.CommandText = string.Format("update login1001 set [name]='{0}', pwd='{1}' where username1001='{0}' ", m_username, m_pswd);
  5. con.open();
  6. try
  7. {
  8. cmd.ExecuteNonQuery();
  9. Label2.Text = "updated successfully";
  10. }
  11. catch (Exception eSql)
  12. {
  13. Label2.Text = "Failed to Update: Error:"+eSql.Message;
  14. }

I prefer to use stored procedures, and the rest of this response is geared towards
that end.

If you want to check to see if these credentials are okay then rewrite your sp_UserValidation like this: (BTW, Never use sp_ as the start of a stored procedure name, because this tells the SQL Plan to first look at the system procs first... waste of time and resources)
C# Syntax (Toggle Plain Text)
  1. create procedure proc_ValidateUser @UserName varchar(50), @UserPassword varchar(20)
  2. AS
  3. if not exists (select top 1 username from Login1 where username=@UserName and
  4. userpassword=@UserPassword)
  5. raiserror('Invalid User',16,1)
  6. GO

Or you could write it to return a scalar value of 1 or 0. SQL defaults to returning a zero if the procedure executed without any errors.

Now if you really want to update some additional information... and this is also the login check then write a stored procedure like this:
C# Syntax (Toggle Plain Text)
  1. create procedure proc_UserValidation @UserName varchar(50),@UserPassword varchar(20)
  2. ,@useraddress varchar(100),@usercity varchar(20),@userpostal int
  3. ,@userphone int,@usermobile int,@Email varchar(30),@website varchar(30)
  4. AS
  5. if not exists (select top 1 username from Login1 where username=@UserName and userpassword=@UserPassword)
  6. raiserror('Invalid User',16,1)
  7. else
  8. begin
  9. update Login1 set useraddress=@useraddress
  10. ,usercity=@usercity
  11. ,userpostal = @userpostal
  12. , userphone = @userphone
  13. , usermobile = @usermobile
  14. , email = @email
  15. , website = @website
  16. where username = @UserName and userpassword=@UserPassword
  17. end

In C# you want to just perform the Login validation then do this, and write another
stored procedure to handle the update of address, city,etc.
C# Syntax (Toggle Plain Text)
  1. string m_username = "Whatever this user name is";
  2. string m_pswd = "whatever the password is";
  3.  
  4. SqlConnection conn = new SqlConnection("userid=sa;password=vubrain;database=raghu;data source=vubrain4");
  5.  
  6. SqlCommand cmd = new SqlCommand("proc_ValidateUser", con);
  7. cmd.CommandType = CommandType.StoredProcedure;
  8. cmd.Parameters.AddWithValue("@UserName", m_uername);
  9. cmd.Parameters.AddWithValue("@UserPassword", m_pswd);
  10.  
  11. con.Open();
  12. try
  13. {
  14. cmd.ExecuteNonQuery();
  15. Label2.Text = "Login successfully";
  16. }
  17. catch (Exception eSql)
  18. {
  19. Label2.Text = "Login Failed with: " +eSql.Message;
  20. }
  21. con.Close();


Hope that Helps,
Jerry
Reputation Points: 69
Solved Threads: 75
Posting Pro in Training
JerryShaw is offline Offline
465 posts
since Nov 2006
Dec 11th, 2007
0

Re: how to update profile of login member

hi jerry, thanks for your codding i will try this
thank you
Reputation Points: 10
Solved Threads: 0
Light Poster
raghu.8 is offline Offline
40 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Compiler Error CS0118
Next Thread in C# Forum Timeline: .class





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC