PDA

View Full Version : چرا دیتا ریدر نمیخونه؟؟؟؟؟



fsima
پنج شنبه 04 بهمن 1386, 15:02 عصر
کد زیر رو تو بر نامه ام مینویسم اما جواب درست رو نمیده



string sqlStr = @"SELECT * from Customer where UserName='" + TextBox1.Text + "' and Password='" + TextBox2.Text + "'";
ConnectionStringSettings settings;
settings = System.Configuration.ConfigurationManager.Connecti onStrings["connStr"];
string connectionString = settings.ConnectionString;
SqlConnection cn = new SqlConnection(connectionString);
cn.Open();
SqlCommand cmd = new SqlCommand(sqlStr, cn);
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{

int id = Convert.ToInt16(dr["mid"]);
Response.Redirect("Default2.aspx?mid=" + id);
dr.Close();


به if که می رسه داخل حلقه نمیره در صورتی که باید بره
وقتی هم که ifرو برمیدارم و فقط مینویسم dr.read() اون وقت خط بعدی خطا میده که:

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.

واقعا گیج شدم
کد webconfing هم اینه


<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings/>
<connectionStrings >
<add name="connStr" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Hamidiya\Desktop\WebSite\Camera.mdf;Integ rated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient;" />


قبلا همین کد ها رو واسه یه برنامه دیگه نوشتم و جواب داده
فرق اون برنامه با این یکی تو اینه که دیتا بیس اون رو مستقیم تو خود محیط SqlServer ساختم و اینو تو از توی دات نت
خیلی ممنون میشم اگه کمک ام کنید چون همه چی رو امتحان کردم

Alireza_Salehi
پنج شنبه 04 بهمن 1386, 16:07 عصر
Password از کلمات کلیدی SQL است اینطوری استفاده کنید:

[Password]