简单的数据库链接,操作
public void Add()
{
String ConnectionString = "Server=.;UID=sa;Pwd=1;Database=SS";
SqlConnection Conn = new SqlConnection(ConnectionString);
Conn.Open();
String CommandString = "Insert Into SS1(SD,SS) Values(@SD,@SS)";
SqlCommand Cmd = new SqlCommand(CommandString, Conn);
//定义参数的方法
//SqlParameter Parm = new SqlParameter();
//Parm = new SqlParameter("@SD",SqlDbType.VarChar);
//Parm.Value = TextBox1.Text;
//Cmd.Parameters.Add(Parm);
//多个参数
SqlParameter[] Parm = new SqlParameter[2];
Parm[0] = new SqlParameter("@SD", SqlDbType.VarChar);
Parm[1] = new SqlParameter("@SS",SqlDbType.VarChar);
Parm[0].Value = TextBox1.Text;
Parm[1].Value = TextBox2.Text;
foreach (SqlParameter P in Parm)
{
Cmd.Parameters.Add(P);
}
SqlDataAdapter da = new SqlDataAdapter(Cmd);
DataSet ds = new DataSet();
da.Fill(ds);
Conn.Close();
Response.Write("<script langguage = javascript>alert('添加成功');</script>");
select();
}