首页/技术开发/内容

dotnet代码自动生成机的完成

技术开发2023-12-19 阅读()
strShortType == "img")
{
sb.Append("\telse\r\n\t") ;
sb.Append(strCommandNull) ;
}
sb.Append("\r\n") ;
}
sb.Append(AddCatchString()) ;

sb.Append("}\r\n") ;
return sb.ToString() ;
}

对于存储过程生成结果集的函数如下:
private string BuildSPGetData(DataSet ds)
{
StringBuilder sb = new StringBuilder() ;
string strFuncParam = "" ;

foreach(DataRow dr in ds.Tables[0].Rows)
{
int iType = (byte)dr["xtype"] ;
string strName = UpFirstChar(dr["name"].ToString().TrimStart('@')) ;
string strType = getType(iType) ;
string strSqlType = getSqlDBType(iType) ;
string strShortType = getTypeShort(iType) ;
strFuncParam = strFuncParam + "\r\n\t\t" + strType + " a" + strShortType + strName + ",";
}
strFuncParam = strFuncParam.TrimEnd(',') ;
string strDef = "public DataSet QuerySP_" + strTableName + "(" + strFuncParam + ")\r\n";
sb.Append(strDef) ;
sb.Append("{\r\n") ;
sb.Append("\tSqlConnection conn = SqlConn.Instance().Connection ;\r\n") ;
sb.Append("\r\n") ;
sb.Append("\tstring strSPName = \"" + strTableName + "\" ;\r\n") ;
sb.Append("\tSqlCommand command = new SqlCommand(strSPName,conn) ;\r\n");
sb.Append("\tcommand.CommandType = CommandType.StoredProcedure ;\r\n") ;
sb.Append("\r\n") ;

foreach(DataRow dr in ds.Tables[0].Rows)
{
int iType = (byte)dr["xtype"] ;
string strParaName = dr["name"].ToString() ;
string strName = UpFirstChar(strParaName.TrimStart('@')) ;
string strSqlType = getSqlDBType(iType) ;
string strShortType = getTypeShort(iType) ;
string strvalue = " a" + strShortType + strName ;
int iLen = (Int16)dr["prec"] ;

string strLen = "" ;
if (strShortType == "str")
strLen = strLen + "," + iLen ;

string strCommandAdd = "\tcommand.Parameters.Add(\"" + strParaName + "\"," + strSqlType + strLen + ") ;\r\n";
string strCommandvalue = "\tcommand.Parameters[\"" + strParaName + "\"].value=" + strvalue + " ;\r\n";
string strCommandNull = "\tcommand.Parameters[\"" + strParaName + "\"].value= DBNull.value ;\r\n";
sb.Append(strCommandAdd) ;
if (strShortType == "dt")
sb.Append("\tif (" + strvalue + "!= DateTime.Minvalue )\r\n\t") ;
else if (strShortType == "str")
sb.Append("\tif (" + strvalue + "!= null )\r\n\t") ;
else if (strShortType == "img")
sb.Append("\tif (" + strvalue + "!= null )\r\n\t") ;
else
sb.Append("") ;
sb.Append(strCommandvalue) ;
if (strShortType == "dt" (北联网教程,专业提供视频软件下载)

第1页  第2页  第3页  第4页  第5页  第6页  第7页  第8页  第9页  第10页  第11页  第12页  第13页 

……

相关阅读