sql - index out of range exception was unhandled in c# -
this question has answer here:
- max(id) using sqldatareader c# 2 answers
this code retrieve inserted product_id got exception here - "index out of range" product_id
public int getproductidd() { int productid = 0; con.open(); string str = "select max(product_id) addproduct"; cmd = new sqlcommand(str, con); sqldatareader rd = cmd.executereader(); while (rd.read()) { productid = convert.toint32(rd["product_id"]); } return productid; }
my database table addproduct follows-
product_id product_name vendor_id ----------------------------------------- 1 asd 3
thanks in advance...
try alias name:
string str = "select max(product_id) product_id addproduct";
analysis:
with query, result like:
max(product_id) 1
and trying fetch product_id
field result.
with alias name, result like:
product_id 1
Comments
Post a Comment