Hello,
I'm getting the error below...
The connection was not closed. The connection's current state is open.
And heres the code thats casung the problem,...
publicstaticvoid JoinGroup(string GroupID,string User_ID){
SqlCommand cmd =newSqlCommand("insert into User_Joined_Groups (GroupID, User_ID) values (@.GroupID, @.User_ID)", conn);conn.Open();
cmd.Parameters.Add(newSqlParameter("@.GroupID", GroupID));cmd.Parameters.Add(newSqlParameter("@.User_ID", User_ID));
cmd.ExecuteNonQuery();
conn.Close();
}
The method is called on a button click
anyone know what I've done wrong?
Thank you
Open your connection before using it when establishing your command. Also, make sure you have created your connection with the proper connection string before opening it:
public static void JoinGroup(string GroupID,string User_ID) {conn =new SqlConnection(connStr);conn.Open();SqlCommand cmd =new SqlCommand("insert into User_Joined_Groups (GroupID, User_ID) values (@.GroupID, @.User_ID)", conn); cmd.Parameters.Add(new SqlParameter("@.GroupID", GroupID));cmd.Parameters.Add(new SqlParameter("@.User_ID", User_ID)); cmd.ExecuteNonQuery();conn.Close();}
|||
champion!
No comments:
Post a Comment