本文介绍了错误16无法将类型'object'隐式转换为'string'。存在显式转换(您是否错过了演员?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public string generateFNo()
            {
                String str = "SELECT Max(fdk_No) From tblFeedback";
                string fNo = null;
                SqlCommand con = new SqlCommand(str, cn);
                cn.Open();

                if (con.ExecuteScalar().Equals(DBNull.Value))
                {
                    fNo = "F01";
                }
                else
                {
                     fNo = con.ExecuteScalar();

         //Display the new fdkno (by get the last fdkno  from db)+1
                    string[] splitCode = Strings.Split(fNo, "F", 2);
                  fNo = "F0" + ((Convert.ToInt32(splitCode[1])) + 1).ToString();
                }

                cn.Close();
            }
        }

推荐答案

Quote:

fNo = con.ExecuteScalar();

fNo = con.ExecuteScalar();

to

to

fNo = (string) con.ExecuteScalar();



这篇关于错误16无法将类型'object'隐式转换为'string'。存在显式转换(您是否错过了演员?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 13:45