-------- 调用存储过程,连接控件参数,显示数据
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.;Database=qdxt;Integrated Security=SSPI";
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
mandType = CommandType.StoredProcedure;
mandText = "proc_shiyanshishiyongliang";
SqlParameter pa = new SqlParameter("@sh_sh_id", SqlDbType.Char);
pa.Value = DropDownList1.SelectedItem.ToString();
comm.Parameters.Add(pa);
comm.Parameters.Add("@shiyongliang", SqlDbType.Int).Direction = ParameterDirection.Output;
comm.ExecuteScalar();
int i = (int)comm.Parameters["@shiyongliang"].Value;
TextBox1.Text = i.ToString();
------ 代码连接数据库查询结果
string y_name = TextBox1.Text;
string y_mima = TextBox2.Text;
string y_leixing=DropDownList1.Text;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "data source=.;database=qdxt;Integrated Security=SSPI";
conn.Open();
SqlCommand com = new SqlCommand();
com.Connection = conn;
mandText = "select * from yh where y_name=@y_name and y_mima=@y_mima and y_leixing=@y_leixing";
SqlParameter pa = new SqlParameter("@y_name", SqlDbType.VarChar,10);
pa.Value = y_name;
com.Parameters.Add(pa);
pa = new SqlParameter("@y_mima", SqlDbType.VarChar, 10);
pa.Value = y_mima;
com.Parameters.Add(pa);
pa = new SqlParameter("@y_leixing", SqlDbType.VarChar,10);
pa.Value = y_leixing;
com.Parameters.Add(pa);
SqlDataReader re = com.ExecuteReader();
if (re.Read())
if (y_leixing == "guanliyuan")
Response.Redirect("kcanpai.aspx");
else
Response.Redirect("新文件夹1/chuqinchaxun.aspx");
else
Response.Write("<script language='javascript'>alert('密码或用户名错误');</script>");
-----------代码连接数据库增删改
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "data source=.;database=qdxt;Integrated Security=SSPI";
conn.Open();
SqlCommand com = new SqlCommand();
com.Connection = conn;
mandText = "insert into dbo.kc(kc_id,kc_name) values(@kc_id,@kc_name)";
SqlParameter pa = new SqlParameter("@kc_id", SqlDbType.NChar, 10);
pa.Value = TextBox1.Text;
com.Parameters.Add(pa);
pa = new SqlParameter("@kc_name", SqlDbType.VarChar, 10);
pa.Value = TextBox2.Text;
com.Parameters.Add(pa);
int i = com.ExecuteNonQuery();
if (i != 0)
{
Response.Write("<script language='javascript'>alert('添加数据成功');</script>");
}
else
{
Response.Write("<script language='javascript'>alert('添加数据失败');</script>");
}
Response.Redirect("kcshezhi.aspx");