hi guys
i am working on a project with c#-asp.net. I trying to send the same message more than one person. I have a message table on my db and messages are sending and bringing on username. Every user has a username.
I taking the query and fill the datatable with the student table's columns. Cause i want to use students' username, so the messages will be sent to the students. Then i give the parameters to the sql command.
Code:
DataTable dtUn = DBCodes.DataGetir("SELECT * FROM student WHERE proj_taken=0");
for (int b = 0; b < dtUn.Rows.Count; b++)
{
uname = dtUn.Rows[b]["stu_username"].ToString();
cmdSend.Parameters.Clear(); //if make it comment the error comes but message will be send to the last person on the datatable again
cmdSend.Parameters.AddWithValue("@receiver", uname);//If write the row here message will send to the last person on the datatable
}
cmdSend.Parameters.AddWithValue("@sender", Session["adusername"].ToString());
cmdSend.Parameters.AddWithValue("@unopened", 1);
cmdSend.Parameters.AddWithValue("@opened", 0);
cmdSend.Parameters.AddWithValue("@context", context);
cmdSend.Parameters.AddWithValue("@title", title);
cmdSend.Parameters.AddWithValue("@senderName", Session["adname"].ToString() + " " + Session["adsname"].ToString());
conSend.Open();
cmdZero.ExecuteNonQuery();
cmdSend.ExecuteNonQuery();
conSend.Close();
the error is The variable name '@receiver' has already been declared. Variable names must be unique within a query batch or stored procedure.
Must declare the scalar variable "@sender".
how can i fix the problem
thanks..