01/10/2018, 08:49
Lấy dữ liệu từ SQL sever
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
namespace WpfApplication2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
Window1 st;
private void btnlogin_Click(object sender, RoutedEventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=WELCOM-PCSQLEXPRESS;Initial Catalog=Test;Integrated Security=True");
SqlDataAdapter sdt = new SqlDataAdapter("Select count (*) from login where id='" + txtid.Text + "'and pass = '" + txtpass.Password + "'", con);
if (txtid==1)
{
if (txtpass.ToString()== 1)
{
this.Hide();
st = new Window1();
st.Show();
}
else
{
MessageBox.Show("Login Failed");
}
}
else
{
MessageBox.Show("Buon");
}
}
}
}
Đậy là đoạn code về phần giao diện màn hình đăng nhập của mình. Và mình đang bí ở chỗ lấy dữ liệu từ database để truy cập vào wpf form khác. Anh em có thể giúp mình
Bài liên quan
Bạn đã biết cách kết nối đến server thì hãy dùng câu query lấy dữ liệu từ server đi, đưa vào các tham số tương ứng là ID và Pass, nếu giá trị trả về khác null tức là có người dùng này thì cho phép mở form kia, vậy là đc.
Xem lệnh query ở https://www.w3schools.com/sql/default.asp nhé.
cảm ơn bạn nha vấn đề của mình đã được giải quyết