怎样C# 写一个winform登录与注册的应用程序?
1个回答
展开全部
登录就是判断你输入的值和数据库中的值是否相同,而注册其实就是往数据库中插入用户名和密码,比如注册代码如下,导入命名空间using System.Data.SqlClient;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=.;database=数据库名;uid=用户名;pwd=密码;";
string strcmd = "insert into 用户表 values('" + TextBox1.Text + "','" + TextBox2.Text + "')";
SqlCommand mycommand = new SqlCommand(strcmd, conn);
try
{
conn.Open();
mycommand.ExecuteNonQuery();
MessageBox.Show(" 注册成功 ");
}
catch
{
MessageBox.Show("注册发生错误");}
finally
{
conn.Close();
}
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=.;database=数据库名;uid=用户名;pwd=密码;";
string strcmd = "insert into 用户表 values('" + TextBox1.Text + "','" + TextBox2.Text + "')";
SqlCommand mycommand = new SqlCommand(strcmd, conn);
try
{
conn.Open();
mycommand.ExecuteNonQuery();
MessageBox.Show(" 注册成功 ");
}
catch
{
MessageBox.Show("注册发生错误");}
finally
{
conn.Close();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询