本文介绍了CompanyId是autoincrement one的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我的代码如下 public string getMaxID() { try { SqlCommand cmd = new SqlCommand( select MAX(Companyid) )来自Customer_Registration的+1,con); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); return dr [ 0 ]。ToString(); } catch (Exception ex) { lblmessage.Text = ex.ToString(); } } 受保护 void btnnew_Click( object sender,EventArgs e) { int companyid; companyid = Convert.ToInt32(getMaxID()); companyid ++; ddlCompanyid.SelectedItem.Text = C000 + companyid.ToString(); } 当我在上面运行代码时显示错误如下 'Customer_Registration.getMaxID()':并非所有代码路径都返回值 什么是我的代码中的错误 问候 narasiman P. 解决方案 My code as follows public string getMaxID() { try { SqlCommand cmd = new SqlCommand("select MAX(Companyid)+1 from Customer_Registration", con); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); return dr[0].ToString(); } catch (Exception ex) { lblmessage.Text = ex.ToString(); } }protected void btnnew_Click(object sender, EventArgs e) { int companyid; companyid = Convert.ToInt32(getMaxID()); companyid++; ddlCompanyid.SelectedItem.Text = "C000" + companyid.ToString(); }when i run above code shows error as follows'Customer_Registration.getMaxID()': not all code paths return a valuewhat is the mistake in my coderegardsnarasiman P. 解决方案 这篇关于CompanyId是autoincrement one的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-30 09:27