62,041
社区成员
发帖
与我相关
我的任务
分享
public string getMaxNo()
{
string no;
//获取数据库最大编号
string s=DBHelper.getMax(表名,列名);
if(string.isNullOrEmpty(s)) //数据库没有
{
no="1000001"; //初始化一个编号
}else{ //有的时候
no=s++;
}
return no;
}
public FSTP_ADPMS_GeogIndiInfo GetModelBySql1(Guid ID,string CertNo)
{
StringBuilder sbSql = new StringBuilder();
sbSql.Append(@"SELECT ID,CertNo,RegName,RegPero,CertDate,ProdSca,QCCode,OrganiseUnitID,PicCode,Remark,CreatedBy,CreatedDate,ModifiedBy,ModifiedDate
FROM [FSTP_ADPMS_GeogIndi]
WHERE CertNo=@CertNo and ID<>@ID");
int n = 0;
SqlParameter[] parameters = {
new SqlParameter("@CertNo", SqlDbType.VarChar,50),
new SqlParameter("@ID", SqlDbType.UniqueIdentifier) };
parameters[n++].Value = CertNo;
parameters[n++].Value = ID;
FSTP_ADPMS_GeogIndiInfo model = null;
//执行查询
using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.LocalFSTP_ADPMSConnectionString, CommandType.Text, sbSql.ToString(), parameters))
{
if (rdr.Read())
{
model = new FSTP_ADPMS_GeogIndiInfo();
model.ID = (new Guid(rdr[FSTP_ADPMS_GeogIndiInfo.ID_FIELD].ToString()));
model.CertNo = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.CERTNO_FIELD]) ? string.Empty : rdr[FSTP_ADPMS_GeogIndiInfo.CERTNO_FIELD].ToString();
model.RegName = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.REGNAME_FIELD]) ? string.Empty : rdr[FSTP_ADPMS_GeogIndiInfo.REGNAME_FIELD].ToString();
model.RegPero = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.REGPERO_FIELD]) ? string.Empty : rdr[FSTP_ADPMS_GeogIndiInfo.REGPERO_FIELD].ToString();
model.CertDate = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.CERTDATE_FIELD]) ? Convert.ToDateTime("1900-1-1") : Convert.ToDateTime(rdr[FSTP_ADPMS_GeogIndiInfo.CERTDATE_FIELD]);
model.ProdSca = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.PRODSCA_FIELD]) ? string.Empty : rdr[FSTP_ADPMS_GeogIndiInfo.PRODSCA_FIELD].ToString();
model.QCCode = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.QCCODE_FIELD]) ? string.Empty : rdr[FSTP_ADPMS_GeogIndiInfo.QCCODE_FIELD].ToString();
model.OrganiseUnitID = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.ORGANISEUNITID_FIELD]) ? int.MinValue : Convert.ToInt32(rdr[FSTP_ADPMS_GeogIndiInfo.ORGANISEUNITID_FIELD]);
model.PicCode = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.PICCODE_FIELD]) ? (new Guid()) : (new Guid(rdr[FSTP_ADPMS_GeogIndiInfo.PICCODE_FIELD].ToString()));
model.Remark = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.REMARK_FIELD]) ? string.Empty : rdr[FSTP_ADPMS_GeogIndiInfo.REMARK_FIELD].ToString();
model.CreatedBy = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.CREATEDBY_FIELD]) ? string.Empty : rdr[FSTP_ADPMS_GeogIndiInfo.CREATEDBY_FIELD].ToString();
model.CreatedDate = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.CREATEDDATE_FIELD]) ? Convert.ToDateTime("1900-1-1") : Convert.ToDateTime(rdr[FSTP_ADPMS_GeogIndiInfo.CREATEDDATE_FIELD]);
model.ModifiedBy = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.MODIFIEDBY_FIELD]) ? string.Empty : rdr[FSTP_ADPMS_GeogIndiInfo.MODIFIEDBY_FIELD].ToString();
model.ModifiedDate = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.MODIFIEDDATE_FIELD]) ? Convert.ToDateTime("1900-1-1") : Convert.ToDateTime(rdr[FSTP_ADPMS_GeogIndiInfo.MODIFIEDDATE_FIELD]);
}
}
return model;
}
这样不就行了,你什么都不会,还是先学习下最基础的知识后在来看这些代码 public FSTP_ADPMS_GeogIndiInfo GetModelBySql1(Guid ID,string CertNo)
{
StringBuilder sbSql = new StringBuilder();
sbSql.Append(@"SELECT ID,CertNo,RegName,RegPero,CertDate,ProdSca,QCCode,OrganiseUnitID,PicCode,Remark,CreatedBy,CreatedDate,ModifiedBy,ModifiedDate
FROM [FSTP_ADPMS_GeogIndi]
WHERE CertNo=@CertNo and ID<>@ID");
int n = 0;
SqlParameter[] parameters = {
new SqlParameter("@CertNo", SqlDbType.VarChar,50),
new SqlParameter("@ID", SqlDbType.UniqueIdentifier) };
parameters[n++].Value = CertNo;
parameters[n++].Value = ID;
FSTP_ADPMS_GeogIndiInfo model = null;
//执行查询
using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.LocalFSTP_ADPMSConnectionString, CommandType.Text, sbSql.ToString(), parameters))
{
model = new FSTP_ADPMS_GeogIndiInfo();
if (rdr.Read())
{
model.ID = (new Guid(rdr[FSTP_ADPMS_GeogIndiInfo.ID_FIELD].ToString()));
model.CertNo = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.CERTNO_FIELD]) ? string.Empty : rdr[FSTP_ADPMS_GeogIndiInfo.CERTNO_FIELD].ToString();
model.RegName = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.REGNAME_FIELD]) ? string.Empty : rdr[FSTP_ADPMS_GeogIndiInfo.REGNAME_FIELD].ToString();
model.RegPero = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.REGPERO_FIELD]) ? string.Empty : rdr[FSTP_ADPMS_GeogIndiInfo.REGPERO_FIELD].ToString();
model.CertDate = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.CERTDATE_FIELD]) ? Convert.ToDateTime("1900-1-1") : Convert.ToDateTime(rdr[FSTP_ADPMS_GeogIndiInfo.CERTDATE_FIELD]);
model.ProdSca = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.PRODSCA_FIELD]) ? string.Empty : rdr[FSTP_ADPMS_GeogIndiInfo.PRODSCA_FIELD].ToString();
model.QCCode = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.QCCODE_FIELD]) ? string.Empty : rdr[FSTP_ADPMS_GeogIndiInfo.QCCODE_FIELD].ToString();
model.OrganiseUnitID = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.ORGANISEUNITID_FIELD]) ? int.MinValue : Convert.ToInt32(rdr[FSTP_ADPMS_GeogIndiInfo.ORGANISEUNITID_FIELD]);
model.PicCode = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.PICCODE_FIELD]) ? (new Guid()) : (new Guid(rdr[FSTP_ADPMS_GeogIndiInfo.PICCODE_FIELD].ToString()));
model.Remark = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.REMARK_FIELD]) ? string.Empty : rdr[FSTP_ADPMS_GeogIndiInfo.REMARK_FIELD].ToString();
model.CreatedBy = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.CREATEDBY_FIELD]) ? string.Empty : rdr[FSTP_ADPMS_GeogIndiInfo.CREATEDBY_FIELD].ToString();
model.CreatedDate = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.CREATEDDATE_FIELD]) ? Convert.ToDateTime("1900-1-1") : Convert.ToDateTime(rdr[FSTP_ADPMS_GeogIndiInfo.CREATEDDATE_FIELD]);
model.ModifiedBy = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.MODIFIEDBY_FIELD]) ? string.Empty : rdr[FSTP_ADPMS_GeogIndiInfo.MODIFIEDBY_FIELD].ToString();
model.ModifiedDate = Convert.IsDBNull(rdr[FSTP_ADPMS_GeogIndiInfo.MODIFIEDDATE_FIELD]) ? Convert.ToDateTime("1900-1-1") : Convert.ToDateTime(rdr[FSTP_ADPMS_GeogIndiInfo.MODIFIEDDATE_FIELD]);
}
}
return model;
}
这个了,直接用sql语句,的怎么写??@"SELECT ID,CertNo,RegName,RegPero,CertDate,ProdSca,QCCode,OrganiseUnitID,PicCode,Remark,CreatedBy,CreatedDate,ModifiedBy,ModifiedDate FROM [FSTP_ADPMS_GeogIndi] WHERE CertNo=@CertNo and ID<>@ID
给我写一下,if和sql都不会