- 书写数据库语句
string str = ConfigurationManager.ConnectionStrings["Con"].ConnectionString;
sqlConnection conn = new sqlConnection(str);
- 打开数据库连接
conn.open();
3.书写sql语句
string sql = "insert into info values(@name,@pwd,@person,@ID,@phone,@email)";
4.使用并书写参数化命令
sqlCommand cmd = new sqlCommand(sql, conn);
sqlParameter[] paras = new sqlParameter[]
{ new sqlParameter("@name",TextBox1.Text),
new sqlParameter("@pwd",TextBox3.Text),
new sqlParameter("@person",TextBox4.Text),
new sqlParameter("@ID",TextBox5.Text),
new sqlParameter("@phone",TextBox6.Text),
new sqlParameter("@email",TextBox7.Text),
};
5.Parameters.AddRange的AddRange可以一次将一个集合或数组添加到Parameters集合
cmd.Parameters.AddRange(paras);
发送
if (cmd.ExecuteNonQuery() > 0)
Write("成功");
else
Write("请联系管理员");
原文地址:https://blog.csdn.net/PaSifaLL/article/details/104818848
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。