0
public void GetUsersDetails(Guid i)
{
StringBuilder sb = new StringBuilder();
sb.Append("DECLARE @NumberOfThreadsByOneUser smallint;");
sb.Append(" SET=(SELECT COUNT(t.threadID)");
sb.Append(" FROM Threads AS t");
sb.Append(" INNER JOIN Users AS u ON u.UsersID=t.UsersID");
sb.Append(" WHERE [email protected])");
string myConnectionString = AllQuestionsPresented.connectionString;
using (SqlConnection conn = new SqlConnection())
{
SqlCommand cmd = new SqlCommand(sb.ToString(), conn);
cmd.Parameters.Add("UserID", SqlDbType.UniqueIdentifier).Value = i;
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
QA = (Int32.TryParse(dr["NumberOfThreadsByOneUser"].ToString(), out result3)) ? int.Parse(dr["Replies"].ToString()) : 0;
}
}
我寫了一條SQL語句,我想得到的是用戶提交的線程數。所以我宣佈了一個smallint變量。但我不確定我的sql語句的語法。我想從結果中讀取。質量保證INT屬性應該收到計數..SQL Count()函數。並設置變量