myconn.open();
mycomm=new SqlCommand("select max(distinct(bus_year)) as bus_year from t_main_business where bus_year="+dtp1.Value.Year.ToString()+"",myconn.con);
if (mycomm.ExecuteScalar()!=null)
{
Int32 bus_year=(Int32)mycomm.ExecuteScalar()+1;
textBox1.Text=bus_year.ToString();
}
else
{
textBox1.Text=dtp1.Value.Year.ToString()+"0001";
}
myconn.close();我这样写有什么地方不对吗?请教高手!多谢!!
mycomm=new SqlCommand("select max(distinct(bus_year)) as bus_year from t_main_business where bus_year="+dtp1.Value.Year.ToString()+"",myconn.con);
if (mycomm.ExecuteScalar()!=null)
{
Int32 bus_year=(Int32)mycomm.ExecuteScalar()+1;
textBox1.Text=bus_year.ToString();
}
else
{
textBox1.Text=dtp1.Value.Year.ToString()+"0001";
}
myconn.close();我这样写有什么地方不对吗?请教高手!多谢!!
解决方案 »
- 一函数参数为 Type 请问在函数体中如何创建这个Type 类型的对象呢?
- 未将对象引用设置到对象实例的问题
- 请问如何使用递归方式,显示TreeView1控件某一节点下的 所有 分支节点名称?
- 小弟在高校教务处工作4年了,想找一个业务规划软件来梳理教学工作,请前辈出招!
- 问个关于C# MarshalAs 的问题 很郁闷
- SharePoint的配置问题
- listView1如何同时添加两张表的记录
- 关于打印的一个小问题,快快来看看呀
- 请问:有关System.Diagnostics.Process的问题
- 大家帮帮忙,很急,C#如何XmlNode转换为XmlDocument
- 求一插值算法,100分相送
- WinForm程序发邮件,如果邮件没有添加附件,发送正常.当添加附件后出现 未能访问“CDO.Message”对象 错误提示
未处理的“System.InvalidCastException”类型的异常出现在 byg.exe 中。其他信息: 指定的转换无效。即:Int32 bus_year=(Int32)mycomm.ExecuteScalar()+1;
datetime ??如果是datetime的话 就必须在两边加上 ‘ ’
myconn 是我写的数据库连接公共类
执行时没有语法错误。
不知道我写的对不对?
{
LogManager.WriteLog("Execute " + strSQL);
try
{
SqlCommand cmd = new SqlCommand(strSQL, this.conn);
if (this.trans != null)
{
cmd.Transaction = this.trans;
}
cmd.CommandType = CommandType.Text;
LogManager.WriteLog("Success"); return cmd.ExecuteNonQuery();
}
catch( Exception ex )
{
LogManager.WriteLog("Failure " + ex.Message );
throw ex;
}
}
public void PrintFinished(SqlConnection cn, SqlTransaction trans, string cd_Kozi, string userName, string programID)
{
//変数の宣言
string strSql = "";
DataSet ds = null;
DataBase db = new DataBase(cn, trans); strSql += " SELECT ";
strSql += " DISTINCT SR_KAN_ADDR ";
strSql += " FROM ";
strSql += " KP_KANBAN ";
strSql += " WHERE ";
strSql += " CD_KOZI = '" + DataBase.SqlItemTextChange(cd_Kozi) + "' "; db.ExecSQL(strSql, "KM_KANBAN", out ds); for (int i = 0; i < ds.Tables["KM_KANBAN"].Rows.Count; i++)
{
//SQL文を生成
strSql = "";
strSql += " UPDATE KM_KANBAN ";
strSql += " SET ";
strSql += " QT_KINKO = QT_KINKO + QT_ISSUE_SHEETS - QT_ISSUE_COMPL, ";
strSql += " QT_ISSUE_COMPL = QT_ISSUE_SHEETS, "; //更新footerを作成
strSql += DataBase.GetUpdateFooter(userName,programID); //更新条件
strSql += " WHERE (SR_KAN_ADDR = " + ds.Tables["KM_KANBAN"].Rows[i]["SR_KAN_ADDR"] + ") ";
int ret = db.ExecSQL(strSql);
if (ret == 0)
{
throw new ApplicationException("更新が失敗しました。");
}
}
}