01/10/2018, 08:50

Lập trình c# Window form

Đây là source code đăng nhập và hiện thị thông tin của sinh viên bao gồm kết nối cơ sở dữ liệu:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Login
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btnlogin_Click(object sender, EventArgs e)
        {
            SqlConnection con2 = new SqlConnection(@"Data Source = WELCOM - PCSQLEXPRESS; Initial Catalog = Test; Integrated Security = True");
            SqlDataAdapter sdt = new SqlDataAdapter("Select Cont (*) from login where id='"+txtid.Text+"'and pass = '"+txtpass.Text+"' ",con2);
            DataTable dt = new DataTable();
            if(dt.Rows[0][0].ToString()=="1")
            {
                this.Hide();
                Form3 ss = new Form3();
                ss.Show();
            }
            else
            {
                MessageBox.Show("Login Failed");
            }
            
            
        }

        private void chcheck_CheckedChanged(object sender, EventArgs e)
        {
            if (chcheck.Checked)
            {
                txtpass.UseSystemPasswordChar = false;
            }
            else
            {
                txtpass.UseSystemPasswordChar = true;
            }
        }
    }
}

Thông tin sinh viên:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Login
{
    public partial class Form3 : Form
    {
        SqlConnection conn;
        public Form3()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            string constring = @"Data Source=WELCOM-PCSQLEXPRESS;Initial Catalog=Test;Integrated Security=True";
            conn = new SqlConnection(constring);
            conn.Open();
            HienThi();
        }

        private void Form3_FormClosing(object sender, FormClosingEventArgs e)
        {
            conn.Close();
        }
        public void HienThi()
        {
            string sqlselect = "Select From hocsinh";
            SqlCommand cmd = new SqlCommand(sqlselect, conn);
            SqlDataReader dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(dr);
            dssv.DataSource = dt;
        }

        private void btnadd_Click(object sender, EventArgs e)
        {
            
        }
    }
}

Lỗi của mình gặp phải là Progam doesnot contain a static Main method suitable for enty point? ai giúp mình với

Đăng Trần viết 11:00 ngày 01/10/2018

Thiếu mất cái hàm Main của người ta rồi, bạn nên làm một bài mẫu nhỏ hơn nữa để biết chuong trình nó chạy như thế nào. Để ý cái hàm static void Main()

Trần Hoàn viết 10:52 ngày 01/10/2018

Khi bạn tạo một project Winform, bạn thấy file Program.cs luôn có static void main() chứ?

Phá Hoại viết 10:55 ngày 01/10/2018

mình không thấy bạn ơi, lúc mình tạo window form thì không thấy hàm static void main();

Trần Hoàn viết 11:03 ngày 01/10/2018

Chắc bạn xoá nhầm rồi. Tạo project winform mới từ đầu đi

Phá Hoại viết 10:55 ngày 01/10/2018

bạn ơi mình tạo mới lại rồi vẫn không thấy hàm static main như bạn nói
<img src="https://daynhauhoc.com//daynhauhoc.s3-ap-southeast-1.amazonaws.com/original/3X/e/4/e4c44844b131f95ed2295a12dced4fb4d3f21fc5.png" width=“690” height="388

Phá Hoại viết 10:56 ngày 01/10/2018

ban ơi mình không thấy hàm static main?

Trần Hoàn viết 11:02 ngày 01/10/2018

Bạn chưa dùng VS bao giờ đúng không?

Phá Hoại viết 10:54 ngày 01/10/2018

mình mới tập dùng đó ban

Bài liên quan
0