I have an asp.net page with a button that I want to submit data into a sql database. I'm trying to run an insert command on one table and an update command in another table. I keep getting the error:

Incorrect syntax near ','. 
Line 242:                    cmd.Parameters.AddWithValue("@CLc", CLc);
Line 243:                    cmd.Parameters.AddWithValue("@RMKc", RMKc);
Line 244:                    cmd2.ExecuteNonQuery();
Line 245:                }
Line 246:

I can't seem to see why there's an issue. Maybe there's a better way to do this?

string conn = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
        using (SqlConnection sqlCon = new SqlConnection(conn))
        {
            sqlCon.Open();
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = "INSERT INTO tblHistory4 ([TankNum],[HFt],[HIn]) SELECT @TankNum,@HFt,@HIn";
                cmd.Parameters.AddWithValue("@TankNum", TankNum);
                cmd.Parameters.AddWithValue("@HFt", HFt);
                cmd.Parameters.AddWithValue("@HIn", HIn);
                cmd.Connection = sqlCon;
                cmd.ExecuteNonQuery();
            }
            using (SqlCommand cmd2 = new SqlCommand())
            {
                cmd2.CommandText = "UPDATE GPCurrentGauge4 SET HFt=@HFtc,HIn=@HInc,HFx=@HFxc WHERE TankNumId=@TankNumId";
                cmd2.Parameters.AddWithValue("@TankNumId", TankNumId);
                cmd2.Parameters.AddWithValue("@HFtc", HFtc);
                cmd2.Parameters.AddWithValue("@HInc", HInc);
                cmd2.Parameters.AddWithValue("@HFxc", HFxc);
                cmd2.Connection = sqlCon;
                cmd2.ExecuteNonQuery();
            }
        }
    }
}

}

Related posts

Recent Viewed