输出你的insert命令看看,另外你的station_time列是DtaeTime类型!而你的参数是SqlDbType.VarChar,这样不对!

解决方案 »

  1.   

    你的sql语句中使用了三个参数@start_stop_id,@start_hour,@start_min,而你只增加了两个参数@start_hour,@start_min
      

  2.   

    这只是我的代码的一部分,我把不关键的部分都删除掉了!
    虽然我的参数都是SqlDbType.VarChar类型,
    但我是通过拼凑才得到真正要保存进数据库的值的。比如:'2004-8-18' + ' ' + @start_hour + ':' + @start_min + ':'
      

  3.   

    问题已经解决了!我定义了一个变量来存储这个拼凑的值,
    在作为一个参数存入数据库。cmdInsertRunRecord = new SqlCommand();
    cmdInsertRunRecord.Connection = cn;
    strSql = "declare @new_run_record_id int,@start_stop_id int,@start_time datetime,@end_stop_id int,@end_time datetime;";
    strSql += "select @start_stop_id = stop_id from bus_stop where stop_name = @start_stop;";
    strSql += "select @start_time = '" + txtDate.Text + "' + ' ' + @start_hour + ':' + @start_min + ':00';";
    strSql += "select @end_stop_id = stop_id from bus_stop where stop_name = @end_stop;";
    strSql += "select @end_time = '" + txtDate.Text + "' + ' ' + @end_hour + ':' + @end_min + ':00';";
    strSql += "insert into run_record(run_id,work_no,oclock) values(" + intRunID.ToString() + ",@work_no,@oclock);";
    strSql += "select @new_run_record_id = @@Identity;";
    strSql += "insert into station_time(stop_id,stop_order,station_time,run_record_id) ";
    strSql += "values(@start_stop_id,1,@start_time,@new_run_record_id);";
    strSql += "insert into station_time(stop_id,stop_order,station_time,run_record_id) ";
    strSql += "values(@end_stop_id,2,@end_time,@new_run_record_id);";
    cmdInsertRunRecord.CommandText = strSql;
    cmdInsertRunRecord.Parameters.Add("@work_no", SqlDbType.VarChar, 50, "work_no");
    cmdInsertRunRecord.Parameters.Add("@oclock", SqlDbType.VarChar, 50, "oclock");
    cmdInsertRunRecord.Parameters.Add("@start_stop", SqlDbType.VarChar, 50, "start_stop");
    cmdInsertRunRecord.Parameters.Add("@start_hour", SqlDbType.VarChar, 2, "start_hour");
    cmdInsertRunRecord.Parameters.Add("@start_min", SqlDbType.VarChar, 2, "start_min");
    cmdInsertRunRecord.Parameters.Add("@end_stop", SqlDbType.VarChar, 50, "end_stop");
    cmdInsertRunRecord.Parameters.Add("@end_hour", SqlDbType.VarChar, 2, "end_hour");
    cmdInsertRunRecord.Parameters.Add("@end_min", SqlDbType.VarChar, 2, "end_min");
      

  4.   

    strSql += "insert into station_time(stop_id,stop_order,station_time) ";
    strSql += "values(@start_stop_id,1,'" + @mytime +"');";string mytime=txtDate.Text + " "+ start_hour + ":" + start_min + ":00";
    ....................
    这样更清晰些吧
    然后把mytime传入 @mytime里面去喽。
      

  5.   

    跟happyno7(夕丁)的做法很相似,但我是在Sql语句里定义参数,
    而你是在程序里面。