使用.Net实现数据库连接
学习C#只是个开始,以前自己只让自己学习java,现在不得不学习.net.呵呵见笑了.
string strcon = 服务器连接;
string InsertStr = "insert into UsersInfo (UserName,Password,Gender,Email,"+
"IdentityCard,Telephone,Address,PostNum,UserType,Question,PasswordKey) values( '"
+TextBox1.Text+"','"+TextBox2.Text+"',"+DropDownList1.SelectedIndex.ToString()+",'"
+TextBox4.Text+"','"+TextBox5.Text+"','"+TextBox6.Text+"','"+TextBox7.Text+"','"+TextBox8.Text+"',"+3
+"'"+TextBox9.Text+"','"+TextBox10.Text+"')";
SqlConnection conn = new SqlConnection(strcon);
SqlCommand cmd = new SqlCommand(InsertStr, conn);
conn.Open();
try
{
cmd.ExecuteNonQuery();
}
catch(Exception exec)
{
Response.Write("注册不成功!"+exec.Message);
}
finally {
conn.Close();
}
呵呵,简单的一个插入功能