C#将一个字符串转换成datetime时,先分析该字符串以获取日期,然后再将每个变量纺织到datetime对象中
string strSql = "select * from ic_certificate where cerNo=@cerNo";SQLiteParameter[] para = new SQLiteParameter[]
{
new SQLiteParameter("@cerNo",cer.CerNo)
};
int i = DBHelper.EexcuteScalar(strSql, para);
public static int EexcuteScalar(string strSQL, params SQLiteParameter[] values)
{
SQLiteCommand cmd = new SQLiteCommand(strSQL,Conn);
cmd.Parameters.AddRange(values);
int i = Convert.ToInt32(cmd.ExecuteScalar());
return i;
}
将一个字符串转换成datetime时,先分析该字符串以获取日期,然后再将每个变量纺织到datetime对象中,总是报这个错。可是根本就没涉及到datetime类型啊,cerNo是string类型的 --------------------编程问答-------------------- 可是你转换的是int,不是日期啊 --------------------编程问答-------------------- cmd.ExecuteScalar()返回单条记录,不能转换成int --------------------编程问答--------------------
--------------------编程问答-------------------- ExecuteScalar只返回一个值,
using(IDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)){
while (reader != null && reader.Read()) {
DateTime time = DateTime.Parse(reader["对应的列名"].toString());
}
}
而返回的是多个列
select * from ic_certificate where cerNo=@cerNo
试一试
select cerNo from ic_certificate where cerNo=@cerNo
可以选择其它列。 --------------------编程问答-------------------- 执行查询,并返回查询所返回的结果集中第一行的第一列。忽略其他列或行。
string strSql = "select count(*) from ic_certificate where cerNo=@cerNo";
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/ --------------------编程问答-------------------- select * from ic_certificate where cerNo=@cerNo用ExecuteScalar执行是为了验证是否存在该信息。是可行的。只是这里总出现那个datetime类型的不匹配问题,可是根本就没有设计到那个类型啊。把*换成其他的列也不行,还是会报这样的错误。 --------------------编程问答-------------------- 按5楼说的解决了
--------------------编程问答-------------------- {
string strSql = "update ic_certificate set cerCustomerName=@cerCustomerName,cerApproverName=@cerApproverName,cerApplicationDate=@cerApplicationDate,cerOperationLocation=@cerOperationLocation,cerCalibrateDate=@cerCalibrateDate,cerRecallDate=@cerRecallDate,cerTemprature=@cerTemprature,cerHumidity=@cerHumidity,teuID=@teuID,appID=@appID,intID=@intID,regID=@regID,insID=@insID,stanID=@stanID,userID=@userID,accID=@accID where cerNo=@cerNo";
SQLiteParameter[] para = new SQLiteParameter[]
{
new SQLiteParameter("@customerName",cer1.CerCustomerName),
new SQLiteParameter("@approverName",cer1.CerApproverName),
new SQLiteParameter("@applicationDate",cer1.CerApplicationDate.Date),
new SQLiteParameter("@operationLocation",cer1.CerOperationLocation),
new SQLiteParameter("@calibrateDate",cer1.CerCalibrateDate.Date),
new SQLiteParameter("@recallDate",cer1.CerRecallDate.Date),
new SQLiteParameter("@temprature",cer1.CerTemprature),
new SQLiteParameter("@humidity",cer1.CerHumidity),
new SQLiteParameter("@teuID",cer1.CerTestUnitsID),
new SQLiteParameter("@appID",cer1.CerApperanceID),
new SQLiteParameter("@intID",cer1.CerInteractionID),
new SQLiteParameter("@regID",cer1.CerRegulationID),
new SQLiteParameter("@insID",cer1.CerInstrmentID),
new SQLiteParameter("@stanID",cer1.CerStandardsID),
new SQLiteParameter("@userID",cer1.CerUserID),
new SQLiteParameter("@accID",cer1.CerAccuracyID),
new SQLiteParameter("@cerNo",cer2.CerNo)
};
int i = DBHelper.EexcuteSQL(strSql, para);
return i;
}
public static int EexcuteSQL(string strSQL, params SQLiteParameter[] values)
{
SQLiteCommand cmd = new SQLiteCommand(strSQL,Conn);
cmd.Parameters.AddRange(values);
int i = cmd.ExecuteNonQuery();
return i;
}
Insufficient parameters supplied to the command//提供给命令的参数不足报这个错误 --------------------编程问答-------------------- --------------------编程问答-------------------- 你还笑。。。。。。。。
补充:.NET技术 , C#