SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["DBConnectionString"]);
SqlCommand insertCmd = new SqlCommand("insert into AddressLists(userId,frdName,frdPhone,frdMobilePhone,frdAddress,frdEmail,frdQQ) values(@userId,@Name,@Phone,@MobilePhone,@Address,@Email,@QQ)", conn);
insertCmd.Parameters.Add("@userId", SqlDbType.VarChar, 15);
insertCmd.Parameters.Add("@Name", SqlDbType.VarChar, 10);
insertCmd.Parameters.Add("@Phone", SqlDbType.VarChar, 15);
insertCmd.Parameters.Add("@MobilePhone", SqlDbType.VarChar, 11);
insertCmd.Parameters.Add("@Address", SqlDbType.VarChar, 200);
insertCmd.Parameters.Add("@Email", SqlDbType.VarChar, 50);
insertCmd.Parameters.Add("@QQ", SqlDbType.VarChar, 15);
insertCmd.Parameters["@userId"].Value = Session["userID"].ToString();
insertCmd.Parameters["@Name"].Value = txtName.Text;
insertCmd.Parameters["@Phone"].Value = txtUtel2.Text;
insertCmd.Parameters["@MobilePhone"].Value = txtUtel3.Text;
insertCmd.Parameters["@Address"].Value = txtUaddr.Text;
insertCmd.Parameters["@Email"].Value = txtUemail.Text;
insertCmd.Parameters["@QQ"].Value = txtUQQ.Text;
try
{
conn.Open();
int flag = insertCmd.ExecuteNonQuery();
if (flag > 0)
{
Response.Write("<script language=javascript>alert('成功添加好友记录!')</script>");
}
else
{
Response.Write("<script language=javascript>alert('添加好友记录失败,查看输入是否正确!')</script>");
}
}
catch (System.Exception ee)
{
Response.Write("<script language=javascript>alert('" + ee.Message.ToString() + "')</script>");
}
finally
{
conn.Close();
}
转载于:https://www.cnblogs.com/myufeiyang/archive/2008/08/06/1261640.html