hoe to use execute scalar method in asp.net

Posted by Shanky11 under ASP.NET on 9/21/2013 | Points: 10 | Views : 5087 | Status : [Member] | Replies : 4
SqlCommand cmd2 = new SqlCommand("SELECT IDENT_CURRENT('orders') ", con);
int id=cmd2.ExecuteScalar();


i have to fetch current identity form tempordr table
how can i get this?????




Responses

Posted by: Bandi on: 9/21/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
try this
SqlCommand cmd2 = new SqlCommand("SELECT max(id) from  orders) ", con);

int id=cmd2.ExecuteScalar();


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/21/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
hi,
its better to have one stored procedure to do complete operation. and execute stored procedure in the app....



create procedure usp_insertOrders( @col1 int, @col2 varchar)

as
begin
insert into orders(col1, col2)
values(@col1, @col2);
select scope_identity() as identityValue
end


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 9/23/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
You can see the below link:-

http://dev.mysql.com/doc/refman/5.0/es/connector-net-examples-mysqlcommand.html#connector-net-examples-mysqlcommand-executescalar

Happy Coding
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 10/1/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi Shankar Mishra,

1) Access the following link to know the threads which are opened by you...
http://www.dotnetfunda.com/users/yourforums.aspx?username=shanky11

2) open each thread and click on "Mark as Answer" link( which is available at the end of each reply) if you got help/solution from the replies...

It will help others who is looking for same kind of issues

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response