private void InsertVideoDetails(string VideoId, string VideoTitle, string Description, int ViewCount, string LikeCount, string CommentCount, DateTime PublishedAt)
{
string sql = "INSERT INTO Videos (VideoId, VideoTitle, Description,LikeCount, ViewCount,CommentCount,Published_At) VALUES (@VideoId, @VideoTitle, @Description, @ViewCount,@LikeCount,@CommentCount,@PublishedAt)";
string constring = ConfigurationManager.ConnectionStrings["Cnn"].ConnectionString;
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand(sql))
{
cmd.Parameters.AddWithValue("@VideoId", VideoId);
cmd.Parameters.AddWithValue("@VideoTitle", VideoTitle);
cmd.Parameters.AddWithValue("@Description", Description);
cmd.Parameters.AddWithValue("@ViewCount", ViewCount);
cmd.Parameters.AddWithValue("@LikeCount", LikeCount);
cmd.Parameters.AddWithValue("@CommentCount", CommentCount);
cmd.Parameters.AddWithValue("@PublishedAt", PublishedAt);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
Error -
| Name | Value | Type | |
|---|---|---|---|
| Message | "The parameterized query '(@VideoId nvarchar(11),@VideoTitle nvarchar(100),@Description nv' expects the parameter '@CommentCount', which was not supplied." | string |
Jignesh KumarPosted Mar 23, 2025, 10:14 AM
I believe the order of parameters in your query is still swapped. Please verify the values in the table after the record is inserted.
Ramco RamcoPosted Mar 23, 2025, 5:30 AM
Hi Jignesh
It was Null value issue . Issue has been resolved.
Thanks
Jignesh KumarPosted Mar 23, 2025, 5:02 AM
Hello Ramco,
Just check order of your parameters and datatype of it,
Sophia CarterPosted Mar 22, 2025, 3:42 PM
The error message you're encountering indicates that in your parameterized query, you are missing the parameter value for '@CommentCount'. This issue specifically arises because while setting up your SqlCommand and adding parameters, you inadvertently skipped providing a value for the CommentCount parameter.
To rectify this error, you need to ensure that you add the missing parameter value for CommentCount before executing the query. In your C# code snippet, make sure to include the following line after setting up the parameters:
By adding the above line, you will supply the required value for the '@CommentCount' parameter in your parameterized query. Once you've made this adjustment, you should be able to execute your SQL query without encountering this particular error.
If you have other parameters that are not being supplied correctly according to your query, you should also double-check and ensure that all parameters are set before executing the query. This approach will help you avoid similar errors in the future and improve the robustness of your parameterized queries.
Let me know if you need further assistance or clarification on this topic!