 |
| BOOK: Beginning ASP.NET Databases Also see the forum ASP Databases for more general discussions of ASP database issues not directly related to these books. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

June 21st, 2004, 01:12 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
|
|
How I Can Use Command In Parameterized manner
i was create two parameterized command for different need first 4 querying(using store proc) the database and secound for inserting value into same table in same db what i must to do i am get confused thati must declare new instant of SqlCommand Object or create new instance of it how i can do it .
Regards YoOrD
__________________
YoOrD .
Beauty is not on the face
Beauty is on the heart
~~<<Ghibran Khalil>>~~
|
|

June 21st, 2004, 02:08 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
Dear yoord:
I didnt get u clearly, why do u use a separate command to insert?!
Its better to do all in a SP. I guess u check something or .. & insert into ur Table, so do what ever u do in ur SP & then RUN insert command from SP too!
Can u explane more.
Always:),
Hovik Melkomian.
|
|

June 21st, 2004, 02:09 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Quote:
quote:Originally posted by yoord
i was create two parameterized command for different need first 4 querying(using store proc) the database and secound for inserting value into same table in same db what i must to do i am get confused thati must declare new instant of SqlCommand Object or create new instance of it how i can do it .
Regards YoOrD
|
i am using such this code to do its but it dont work properly
Code:
SqlConnection objConnection=new SqlConnection(strConnection);
if(Page.IsPostBack)
{
SqlCommand objCommand=new SqlCommand("sp_check_user_pass",objConnection);
objCommand.CommandType=CommandType.StoredProcedure;
objCommand.Parameters.Add(new SqlParameter("@username",SqlDbType.NVarChar,50)).Value=username.Text;
objCommand.Parameters.Add(new SqlParameter("@password",SqlDbType.NVarChar,50)).Value=password.Text;
SqlParameter SqlParam=objCommand.Parameters.Add(new SqlParameter("@RowCount" ,SqlDbType.Int));
SqlParam.Direction=ParameterDirection.ReturnValue;
objConnection.Open();
try
{
objCommand.ExecuteNonQuery();
int rowcount=(int)objCommand.Parameters["@RowCount"].Value;
if(rowcount>0)
{
Response.Write(" User Exist Take Another Uaername");
}
else
{
swtch=false;
objConnection=new SqlConnection(strConnection);
strSql="insert into member_info(first,last,username,password,email) values(@first,@last,@username,@password,@email)";//select * from member_info where username=@username and password=@password";//
objCommand.CommandText=strSql;//=new SqlCommand(strSql,objConnection);
//objCommand.CommandType=CommandText;
objCommand.Parameters.Add(new SqlParameter("@first",SqlDbType.NVarChar,50));//.Value=username.Text;
objCommand.Parameters["@first"].Value=first.Text;//"ali";
objCommand.Parameters.Add(new SqlParameter("@last",SqlDbType.NVarChar,50));
objCommand.Parameters["@last"].Value=last.Text;//"12";
objCommand.Parameters.Add(new SqlParameter("@username",SqlDbType.NVarChar,50));
objCommand.Parameters["@username"].Value=username.Text;
objCommand.Parameters.Add(new SqlParameter("@password",SqlDbType.NVarChar,50));
objCommand.Parameters["@password"].Value=password.Text;
objCommand.Parameters.Add(new SqlParameter("@email",SqlDbType.NVarChar,50));
objCommand.Parameters["@email"].Value=email.Text;
objCommand.Connection.Open();
}
|
|

June 21st, 2004, 02:14 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Quote:
quote:Originally posted by yoord
Quote:
|
quote:Originally posted by yoord
|
Quote:
i was create two parameterized command for different need first 4 querying(using store proc) the database and secound for inserting value into same table in same db what i must to do i am get confused thati must declare new instant of SqlCommand Object or create new instance of it how i can do it .
Regards YoOrD
|
i am using such this code to do its but it dont work properly
Code:
SqlConnection objConnection=new SqlConnection(strConnection);
if(Page.IsPostBack)
{
SqlCommand objCommand=new SqlCommand("sp_check_user_pass",objConnection);
objCommand.CommandType=CommandType.StoredProcedure;
objCommand.Parameters.Add(new SqlParameter("@username",SqlDbType.NVarChar,50)).Value=username.Text;
objCommand.Parameters.Add(new SqlParameter("@password",SqlDbType.NVarChar,50)).Value=password.Text;
SqlParameter SqlParam=objCommand.Parameters.Add(new SqlParameter("@RowCount" ,SqlDbType.Int));
SqlParam.Direction=ParameterDirection.ReturnValue;
objConnection.Open();
try
{
objCommand.ExecuteNonQuery();
int rowcount=(int)objCommand.Parameters["@RowCount"].Value;
if(rowcount>0)
{
Response.Write(" User Exist Take Another Uaername");
}
else
{
swtch=false;
objConnection=new SqlConnection(strConnection);
strSql="insert into member_info(first,last,username,password,email) values(@first,@last,@username,@password,@email)";//select * from member_info where username=@username and password=@password";//
objCommand.CommandText=strSql;//=new SqlCommand(strSql,objConnection);
//objCommand.CommandType=CommandText;
objCommand.Parameters.Add(new SqlParameter("@first",SqlDbType.NVarChar,50));//.Value=username.Text;
objCommand.Parameters["@first"].Value=first.Text;//"ali";
objCommand.Parameters.Add(new SqlParameter("@last",SqlDbType.NVarChar,50));
objCommand.Parameters["@last"].Value=last.Text;//"12";
objCommand.Parameters.Add(new SqlParameter("@username",SqlDbType.NVarChar,50));
objCommand.Parameters["@username"].Value=username.Text;
objCommand.Parameters.Add(new SqlParameter("@password",SqlDbType.NVarChar,50));
objCommand.Parameters["@password"].Value=password.Text;
objCommand.Parameters.Add(new SqlParameter("@email",SqlDbType.NVarChar,50));
objCommand.Parameters["@email"].Value=email.Text;
objCommand.Connection.Open();
}
|
|
|

June 21st, 2004, 02:21 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Quote:
quote:Originally posted by melvik
Dear yoord:
I didnt get u clearly, why do u use a separate command to insert?!
Its better to do all in a SP. I guess u check something or .. & insert into ur Table, so do what ever u do in ur SP & then RUN insert command from SP too!
Can u explane more.
Always:),
Hovik Melkomian.
|
Thanx 2 u
i am going to check for a username if it is exist(using SP) if it is exist it is exist i must alert the user to take another username if it is not exist i must to insert it into table.
and i do this in first(SP) and if it is not exist in Command i must build parameters and insert it into table the main problem i get that i dont know how i can do it (if i had create new command boject or create new SqlCommand Object.
Regards YoOrD.
|
|

June 21st, 2004, 02:24 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
Im still in my last believe! check ur Username & insert it if not exist! & do all at a SP & not use another command!
REMEMBER SP's r much fast & ...
Always:),
Hovik Melkomian.
|
|

June 21st, 2004, 02:28 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Quote:
quote:Originally posted by melvik
Im still in my last believe! check ur Username & insert it if not exist! & do all at a SP & not use another command!
REMEMBER SP's r much fast & ...
Always:),
Hovik Melkomian.
|
thanx 2 u i must examine it , it is a good idea.
thanx 2 u again :)
|
|
 |