自动编码生成SQL语句的问题
public string getCode(string paramDateTime)
{
DateTime.Now.ToString("yy mm dd");
string strQuery = @" select Max(Code) from Check
where Code like '%'";
Hashtable myParam = new Hashtable();
myParam.Add("@Code", paramDateTime);
BaseDBCon myBaseDBCon = new BaseDBCon();
DataSet myDs = new DataSet();
string returnValue = string.Empty;
try
{
myBaseDBCon.Open();
myBaseDBCon.Fill(strQuery, myDs, "T", myParam);
if (myDs.Tables[0].Rows[0][0] != DBNull.Value)
{
string Code = myDs.Tables[0].Rows[0][0].ToString();
int Tmp = int.Parse(Code);
Tmp++;
int Count = Code.Length - Tmp.ToString().Length;
for (int i = 0; i < Count; i++)
{
returnValue += "0";
}
returnValue += Tmp.ToString();
}
else if (myDs.Tables[1].Rows.Count > 0)
{
returnValue = myDs.Tables[1].Rows[0][0].ToString() + "001";
}
else
{
returnValue = "001";
}
}
catch (Exception myEx)
{
throw new Exception(myEx.Message + "\r\n SQL:" + strQuery);
}
finally
{
myBaseDBCon.Close();
}
return returnValue;
}
当点击进入页面的时候 想让txtCode框自动生成编码,首先查询当天有无生成过编码,查询条件