sql - index out of range exception was unhandled in c# -


this question has answer here:

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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -