PDA

View Full Version : سوال: شمارش کاربران



Rain_Song
چهارشنبه 28 بهمن 1388, 18:26 عصر
سلام
برای شمارش کل کاربران کد زیر رو به کار بردم :


void Session_Start(object sender, EventArgs e)
{

Application["online"] = Convert.ToInt32(Application["online"]) + 1;
// marboot be hesab kardane kolle karbaran
SqlDataSource ds = new SqlDataSource();
ds.ConnectionString = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;
ds.UpdateCommand = "update usercount set cnt = cnt+1";
ds.Update();
}که در فایل global.asax قرار داره. جدول usercount هم ساختم .
به خط:

ds.ConnectionString = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;error میده . مشکل از کجاست ؟؟؟

m_kalantar.cs
چهارشنبه 28 بهمن 1388, 19:26 عصر
دوست عزیز چه خطایی میده ؟
متن error را قرار بده شاید فرجی شد

Rain_Song
چهارشنبه 28 بهمن 1388, 21:19 عصر
این هم از متن error :

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 28: // marboot be hesab kardane kolle karbaran
Line 29: SqlDataSource ds = new SqlDataSource();
Line 30: ds.ConnectionString = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;
Line 31: ds.UpdateCommand = "update usercount set cnt = cnt+1";
Line 32: ds.Update();