Using a number of queries, as shown in the code below, I get the following exception:
An exception of type 'System.ArgumentOutOfRangeException' - Specified argument was out of the range of valid values
on this line:
e.Row.Cells[3].Text = count;
What could be the problem? I tried countless different things, but I can't get it working. I am a novice at this.
SqlConnection conn;
conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=" + Server.MapPath("~\\App_Data\\ForumDB.mdf") + ";Integrated Security=True;User Instance=True");
conn.Open();
SqlCommand comm;
comm = new SqlCommand("SELECT COUNT(ThreadId) FROM [Threads] WHERE [TopicId] = @TopicId", conn);
SqlCommand comm2;
comm2 = new SqlCommand("SELECT MAX(PostedDate) FROM [Threads] WHERE [TopicId] = @TopicId", conn);
SqlCommand comm3;
comm3 = new SqlCommand("SELECT PostedBy FROM Threads WHERE PostedDate=(SELECT MAX(PostedDate) FROM [Threads] WHERE [TopicId] = @TopicId", conn);
//FOR COMMAND1 CMD
comm.Parameters.Add("@TopicId", System.Data.SqlDbType.Int, 10, "TopicId");
comm.Parameters["@TopicId"].Value = e.Row.Cells[0].Text;
string count = (comm.ExecuteScalar().ToString());
e.Row.Cells[3].Text = count;
//FOR COMMAND2 CMD1
comm2.Parameters.Add("@TopicId", System.Data.SqlDbType.Int, 10, "TopicId");
comm2.Parameters["@TopicId"].Value = e.Row.Cells[0].Text;
string count1 = (comm2.ExecuteScalar().ToString());
e.Row.Cells[4].Text = count1;
//for command3 cmd2
comm3.Parameters.Add("@TopicId", System.Data.SqlDbType.Int, 10, "TopicId");
comm3.Parameters["@TopicId"].Value = e.Row.Cells[0].Text;
if (comm3.ExecuteScalar() != null)
{
count2 = (comm3.ExecuteScalar().ToString());
}
conn.close();
/
Aucun commentaire:
Enregistrer un commentaire