如何将文本框值与c#中的sql数据库值进行比较? [英] How to compare textbox value with the sql database value in c#?
本文介绍了如何将文本框值与c#中的sql数据库值进行比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将文本框值与c#中的sql数据库值进行比较?
我是初学者我必须创建一个项目。我只知道如何将数据库与c#项目连接起来。我没有要求确切的代码,请告诉我任何教程,链接或任何可以帮助我的东西。
还有一件事,我没有sql :(我有下载了许多设置,但它们没有完整。如果有人知道我可以获得的任何网站,请告诉我。
How to compare textbox value with the sql database value in c#?
im a beginner n i have to make a project. i only know how to connect database with the c# project. i m not asking for the exact code, kindly tell me any tutorial, link or anything that can help me.
One thing more, i dont have sql :( i have downloaded many setups but they r not complete. if anyone know any site from where i can get, do tell me please.
推荐答案
我认为这个将指导你.....
I think this will guide you.....
您可以按照以下步骤操作:
1.使用System.Data.SqlClient;
2.
You can follow these steps:
1. using System.Data.SqlClient;
2.
protected void Button1_Click(object sender, EventArgs e)
{
string str = "Data Source=ABC-PC\\SQLEXPRESS;Initial Catalog=demodb;Integrated Security=True";
SqlConnection conn = new SqlConnection(str);
conn.Open();
string adminId = txtadminId.Text;
string password = txtpassword.Text;
string query = "SELECT admin_id, password FROM users WHERE id=@adminId
and password=@password";
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@admin_id", adminId);
cmd.Parameters.AddWithValue("@password", password);
SqlDataReader dr = cmd.ExecuteReader();
希望这个帮助:)
获取更多信息评论!!
hope this helps:)
for more info comment here!!
您可以参考以下链接完成工作:
http://www.csharp-station.com/Tutorials/AdoDotNet/ Lesson1.aspx [ ^ ]
为初学者使用ADO.NET [ ^ ]
希望这有助于:)
You can refer to the following links to get your job done:
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson01.aspx[^]
Using ADO.NET for beginners[^]
hope this helps :)
这篇关于如何将文本框值与c#中的sql数据库值进行比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文