C# 试题作业~寻求解答~

来源:百度知道 编辑:UC知道 时间:2024/06/04 22:48:30
Employee
string name //员工姓名
int age //员工年龄
string address

启动程序:
1、添加一个新员工到文件。
2、可查询到某一员工相关信息。
问题补充:不好意思忘了说了~
要用控制台应用做~

其实很简单,
给你一个添加用户的类,看看就搞定

public static bool AddUser(string name, string age ,string adress)
{
SqlConnection con = new SqlConnection("server=.;database=bbs;uid=sa;pwd=sa");
con.Open();
try
{
string sql = "INSERT IN TO Usertable VALUES ('" + name + "','" + age + "','"+address+"')";
SqlCommand com = new SqlCommand(sql, con);
if (com.ExecuteNonQuery() > 0)
{
return true;
}

}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
con.Close();
}
return false;
}