求C#winform 数据库类(连接和增删改查)和在窗口中的调用代码 请问你有这个模板吗

数据库名 demo 表名 Human 表中4列 id name age address id主键
怎么增加删除表中内容,求详细代码

public const string sqlconn = "Data Source=.;Initial Catalog=hh;Integrated Security=True";

private void butenroa_Click(object sender, EventArgs e)
{
//接受输入
string name = this.texenroa.Text;
string NAME = this.texenrob.Text;
string code = this.texenroc.Text;
string code1 = this.texenrod.Text;
string wenti = this.comboBoxenro1.Text;
string mibao = this.texenroe.Text;

if (name == "" | code == "" | code1 == "" | mibao == ""|wenti==""|NAME=="")
{
MessageBox.Show("注册失败,任何一项不能为空");
return;
}
else if (wenti == "请选择密保问题?")
{
MessageBox.Show("请选择密保问题!");
return;
}
else if (code != code1)
{
MessageBox.Show("密码前后不一致");
return;
}
else if (name.Length > 16 | name.Length < 5)
{
MessageBox.Show("用户名必须是 5-16位");
return;
}

if (!Regex.IsMatch(code, @"^[a-zA-Z0-9]{6,16}$"))
{
MessageBox.Show("密码格式错误,只能是6-16位数字字母的组合!");
return;
}

//打开数据库
SqlConnection conn = new SqlConnection(sqlconn);
conn.Open();

//用户名是主键,检索y用户名是否存在
string sql = "select count(*) from hh where y_name='" + name + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
int i = (int)cmd.ExecuteScalar();
if (i > 0)
{
MessageBox.Show("此用户已存在,请重新注册");
return;
}

//满足条件,允许注册
sql = "insert into hh values('" + name + "','" + NAME + "','" + code + "','" + wenti + "','" + mibao + "','"+""+"')";
SqlCommand com = new SqlCommand(sql, conn);
com.ExecuteNonQuery();
conn.Close();

MessageBox.Show("请记住您的密码问题:" + wenti + "【" + mibao + "】" + ",这是您找回密码的唯一途径");

DialogResult dr = MessageBox.Show("注册成功,是否登录?\n【是】转到登录\n【否】继续注册","选择",MessageBoxButtons.YesNo,MessageBoxIcon.None);
if (dr == DialogResult.Yes) //返回登录
{
Close();
}
else //继续注册
{
this.texenroa.Text = "";
this.texenrob.Text = "";
this.texenroc.Text = "";
this.texenrod.Text = "";
this.texenroe.Text = "";
this.comboBoxenro1.Text = "请选择密保问题?";
}追问

你这从哪儿弄过来的啊,跟我问的不搭界啊

追答

呵呵 ,你想要我把你的那写代码写出来啊?这是个连接的很简单的例子,我中午刚写的,和你的这个事例是一样的!好好看看就懂啦!

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-05-08
string str1=“select * from table”;
string strcon=@"data source=.;uid=sa;pwd=;database=";
SqlConnection con= new SqlConnection(strcon);
SqlDataAdapter da= new SqlDataAdapter(str, con);
con.open();
dataset ds=new dataset();
da.fill(ds);
con.close();追问

我现在会WINDOWS控制台应用程序 不会窗体应用程序,求界面和代码,

追答

这个不差不多吗?再说我的代码发给你,数据库有不一样。明天看看有空不,有空的话做一个发给你

追问

数据库名demo 表名Human 表中4列 id name age address id主键
如何增加删除

第2个回答  2012-05-08
邮箱留下追问

[email protected]

追答

发过去了,采纳吧

追问

这个帮助类有什么用,刚学,不太会,能详细解释。要有做好的,更感谢。

第3个回答  2012-05-08
已发送,自己看着玩吧!追问

能加好友吗?425567434,

本回答被提问者采纳
相似回答