C#登录&与数据库的连接 [英] C# Log in & connection to database
本文介绍了C#登录&与数据库的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过用户名和密码进行注册以及如何添加用户类型和数据库连接以检查用户表中的数据.
请我帮忙一些
how to make registration by user name and password and add type of user and connection to database to check data in users table.
Please i want some of help
推荐答案
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication_toLogIn
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnLogIn_Click(object sender, EventArgs e)
{
// First create DB and table, follow copy/pase connection string
SqlConnection cnn = new SqlConnection("Your connection string");
// For query
SqlDataAdapter da = new SqlDataAdapter("SELECT user, pass FROM yourTable WHERE user='" + txtUser.Text + "' and pass='" + txtPass.Text + "'", cnn);
// fill dataset
DataSet ds = new DataSet();
da.Fill(ds);
// Check trust
if (ds.Tables["yourTable"].Rows.Count > 0)
{
// Log in
}
else
{
// No Log in
}
}
}
}
这篇关于C#登录&与数据库的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文