View Code 1 using (SqlConnection conn = new SqlConnection(connStr)) 2 { 3 string sql = "[PRinserTcheck]";//存储过程名 4 using (SqlCommand cmd = new SqlCommand(sql, conn)) 5 { 6 //执行存储过程 7 cmd.CommandType = CommandType.StoredProcedure; 8 9 cmd.Parameters.AddWithValue("@deldate", txt_date.Value .Trim ()); 10 SqlParameter sp = cmd.Parameters.Add("@selectno", SqlDbType.Int ); 18 sp.Direction = ParameterDirection.Output; 19 20 //执行存储过程 21 conn.Open(); 22 cmd.ExecuteNonQuery(); 23 24 txt_selectNO.Text = sp.Value.ToString(); 25 } 26 }
上面是执行存储过程的,下面是不是存储过程的
cmd.CommandText = "select * from [user] where uUserName=@UserName and uPwd=@Password"; cmd.Parameters.Add(new SqlParameter(“@ UserName ","admin")); cmd.Parameters.Add(new SqlParameter(“@ Password ",password));
其实只用cmd.Parameters.AddWithValue就可以了