HELP: Insert data into SQL table ERROR: Conversion failed when converting date and/or time from character string.

  • Thread starter Thread starter ri_montoya
  • Start date Start date
R

ri_montoya

Guest
Hi, i need to insert data into a SQL database, but i have some problems, can you help me??



SqlCommand cmd = new SqlCommand();

cmd.Parameters.Add("@Batch_ID", SqlDbType.NVarChar, 50).Value = Batch_ID;
cmd.Parameters.Add("@PlantName", SqlDbType.NVarChar, 50).Value =Plant;
cmd.Parameters.Add("@ReportName", SqlDbType.NVarChar, 50).Value =ReportName;
cmd.Parameters.Add("@RepDateTime", SqlDbType.DateTime,23).Value =RepDateTime;
cmd.Parameters.Add("@Operator_Name", SqlDbType.NVarChar, 50).Value =OPname;
cmd.Parameters.Add("@ProdStartDateTim", SqlDbType.DateTime, 23).Value = ProdStartDateTime;
cmd.Parameters.Add("@BatchStartDateTime", SqlDbType.DateTime, 23).Value =BStartDateTime;
cmd.Parameters.Add("@BatchStopDateTime", SqlDbType.DateTime,23).Value = BStopDateTime;
cmd.Parameters.Add("@Recipe_No", SqlDbType.Int,10).Value = RecipeNo;
cmd.Parameters.Add("@Recipe_Name", SqlDbType.NVarChar, 50).Value = RecipeName;
cmd.Parameters.Add("@Recipe_SP", SqlDbType.Real, 24).Value = RecipeSP;
cmd.Parameters.Add("@Recipe_Achieved", SqlDbType.Real, 24).Value = RecipeAch;
cmd.Parameters.Add("@Batch_No", SqlDbType.Int, 10).Value =BatchNo;
cmd.Parameters.Add("@Batches_Total", SqlDbType.Int, 10).Value = BatchTotal;
cmd.Parameters.Add("@Batch_SP", SqlDbType.Real, 24).Value = BatchSP;
cmd.Parameters.Add("@Batch_Achieved", SqlDbType.Real, 24).Value =BatchAch;
cmd.Parameters.Add("@Line", SqlDbType.Int, 10).Value =Line;
cmd.Parameters.Add("@State", SqlDbType.Int, 10).Value = State;
cmd.Parameters.Add("@Executor", SqlDbType.BigInt, 19).Value =Executor;
cmd.CommandText = @"INSERT INTO dbo.batch VALUES ('@Batch_ID','@PlantName','@ReportName','@RepDateTime','@Operator_Name','@ProdStartDateTime','@BatchStartDateTime','@BatchStopDateTime','@Recipe_No','@Recipe_Name','@Recipe_SP','@Recipe_Achieved','@Batch_No','@Batches_Total','@Batch_SP','@Batch_Achieved','@Line','@State','@Executor')";

oDataadapter = new SqlDataAdapter(cmd.CommandText,CC);
odataset = new DataSet();
oDataadapter.Fill(odataset, "batch");

Continue reading...
 
Back
Top