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
Bài liên quan
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()
Khi bạn tạo một project Winform, bạn thấy file Program.cs luôn có
static void main()
chứ?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();
Chắc bạn xoá nhầm rồi. Tạo project winform mới từ đầu đi
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
ban ơi mình không thấy hàm static main?
Bạn chưa dùng VS bao giờ đúng không?
mình mới tập dùng đó ban