我怎样才能从sql中获取? [英] How Can I Fetch from sql?

查看:70
本文介绍了我怎样才能从sql中获取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

label4.Text =;

if(!string.IsNullOrWhiteSpace(textBox1.Text))

{

if(! string.IsNullOrWhiteSpace(textBox2.Text))

{

SqlConnection connect = new SqlConnection(data source ='。'; initial catalog ='fastfood'; integrated security = true;);

connect.Open();

SqlCommand login = new SqlCommand(select admin(*)from admin where name_karbari ='+ textBox1.Text +'和ramze_obur ='+ textBox2.Text +',co​​nnect);

SqlDataReader r;

r = login.ExecuteReader();

int count = 0;

>>>>>>> >>>> while(r.read())

{

count ++;

}

if(count == 1 )//如果条件是真的吗?!登录否则访问被拒绝

{

label4.Text =لاگینشدید。;

}

else if (count == 0)

{

label4.Text =نامکاربرییاپسوردغلطاست。;

}

connect.Close();

}

else

{

label4.Text = رمزعبورنمیتواندخالیباشد。;

}

}

else

{

label4.Text =نامکاربرینمیتواندخالیباشد。;

}

当我运行此代码时,我显示的行有读取问题( );

我该怎么办?

label4.Text = "";
if (!string.IsNullOrWhiteSpace(textBox1.Text))
{
if (!string.IsNullOrWhiteSpace(textBox2.Text))
{
SqlConnection connect = new SqlConnection("data source =' . ';initial catalog='fastfood';integrated security=true;");
connect.Open();
SqlCommand login=new SqlCommand ("Select count (*) from admin where name_karbari='" + textBox1.Text + "' and ramze_obur='" + textBox2.Text + "', connect");
SqlDataReader r;
r = login.ExecuteReader();
int count = 0;
>>>>>>>>>>> while (r.read())
{
count++;
}
if (count == 1)//if is condition is true?! login else access denied
{
label4.Text = "لاگین شدید .";
}
else if(count==0)
{
label4.Text = "نام کاربری یا پسورد غلط است.";
}
connect.Close();
}
else
{
label4.Text = "رمز عبور نمی تواند خالی باشد .";
}
}
else
{
label4.Text = "نام کاربری نمی تواند خالی باشد .";
}
when i run this code، the line which i show has problem with read();
what should i do?

推荐答案

你不需要像PHP一样获取。 PHP并不严肃,特别是与.NET和ADO.NET相比时:

http:/ /en.wikipedia.org/wiki/ADO.NET [ ^ ],

http ://msdn.microsoft.com/en-us/library/e80y5yhx%28v=vs.110%29.aspx [ ^ ]。



这个简短而精心编写的CodeProject文章将帮助您立即入门:使用ADO。 NET适合初学者 [ ^ ]。



-SA
You need not "fetch like PHP". PHP is not something serious, especially when compared to .NET and ADO.NET:
http://en.wikipedia.org/wiki/ADO.NET[^],
http://msdn.microsoft.com/en-us/library/e80y5yhx%28v=vs.110%29.aspx[^].

This short and well-written CodeProject article will help you to get started in no time: Using ADO.NET for beginners[^].

—SA


这篇关于我怎样才能从sql中获取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆