三层之间的关系
CommandType 区别和应用
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Text; using System.Windows.Forms; namespace GZItcastSim { public partial class FTest : Form { public FTest() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("server=.;database=heimablog;uid=sa;pwd=suncoder"); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "EXEC dbo.usp_GetStuPage @pageindex,@pagesize ,@pagecount OUTPUT"; //创建参数对象 SqlParameter sp=new SqlParameter(); sp.ParameterName="@pagecount"; sp.SqlDbType= SqlDbType.Int; sp.Direction = ParameterDirection.Output; cmd.Parameters.Add(new SqlParameter("@pageindex", SqlDbType.Int) { Value = 1 }); cmd.Parameters.Add(new SqlParameter("@pagesize", SqlDbType.Int) { Value = 10 }); cmd.Parameters.Add(sp); //cmd.CommandType = CommandType.Text; conn.Open(); cmd.ExecuteReader(); //只有调用了Execute之后,输出参数对象的 Value 才有值 object obj = sp.Value; } private void button2_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("server=.;database=heimablog;uid=sa;pwd=suncoder"); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "dbo.usp_GetStuPage"; //创建参数对象 SqlParameter sp = new SqlParameter(); sp.ParameterName = "@pagecount"; sp.SqlDbType = SqlDbType.Int; sp.Size = 4000;//如果输出参数是字符串的,那么必须制定长度,否则长度为0 sp.Direction = ParameterDirection.Output; cmd.Parameters.Add(new SqlParameter("@pageindex", SqlDbType.Int) { Value = 1 }); cmd.Parameters.Add(new SqlParameter("@pagesize", SqlDbType.Int) { Value = 10 }); cmd.Parameters.Add(sp); //cmd在执行的时候,会自动的把参数加上去 cmd.CommandType = CommandType.StoredProcedure; conn.Open(); cmd.ExecuteReader(); //只有调用了Execute之后,输出参数对象的 Value 才有值 object obj = sp.Value; } } }
MD5加密问题
epwd = FormsAuthentication.HashPasswordForStoringInConfigFile(epwd, "MD5");
其实就是一句代码的问题,就是在用户输入数据库的时候,转换成MD5值;
然后判断时候输入值与数据库值均是用MD5值来进行判断,准确性能高。
发送邮件静态类
using System; using System.Collections.Generic; using System.Text; using System.Collections; using System.Net.Mail; namespace Comm { public class MailUnit { public string smtp; public string from; public string pwd; public string to; public string title; public string body; public ArrayList paths; /// <summary> /// 发送邮件单元类 /// </summary> /// <param name="Psmtp">SMYP服务器地址</param> /// <param name="Pfrom">发件人地址</param> /// <param name="Ppwd">发件人密码</param> /// <param name="Pto">收件人地址</param> /// <param name="Ptitle">主题</param> /// <param name="Pbody">正文</param> /// <param name="Ppaths"></param> public MailUnit(string Psmtp, string Pfrom, string Ppwd, string Pto, string Ptitle, string Pbody, ArrayList Ppaths) { smtp = Psmtp; from = Pfrom; pwd = Ppwd; to = Pto; title = Ptitle; body = Pbody; paths = Ppaths; } /*发邮件*/ public bool SendMail() { //创建smtpclient对象 System.Net.Mail.SmtpClient client = new SmtpClient(); client.Host = smtp; client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(from, pwd); client.DeliveryMethod = SmtpDeliveryMethod.Network; //创建mailMessage对象 System.Net.Mail.MailMessage message = new MailMessage(from, to); message.Subject = title; //正文默认格式为html message.Body = body; message.IsBodyHtml = true; message.BodyEncoding = System.Text.Encoding.UTF8; //添加附件 if (paths!=null && paths.Count != 0) { foreach (string path in paths) { Attachment data = new Attachment(path, System.Net.Mime.MediaTypeNames.Application.Octet); message.Attachments.Add(data); } } try { client.Send(message); return true; }//MessageBox.Show("邮件发送成功."); catch (Exception ex) { return false; }//MessageBox.Show("邮件发送失败." + ex.ToString()); } } }
NPOIS
用于中文判断拼音等问题。并没有听太懂。