Code
string strSql = "";
SqlConnection sqlCon = new SqlConnection(HeadStartConnString);
SqlCommand sqlCommStoreProcedue = new SqlCommand();
sqlCommStoreProcedue.Connection = sqlCon;
sqlCommStoreProcedue.CommandType = CommandType.Text;
if (chk.Checked)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
strSql = "Create PROCEDURE #ImgeUpdate \n @RptImage Image, \n @RptDescription varchar(1000) \n as update Reports set RptImage = @RptImage, RptDescription = @RptDescription where RptID = " + rptID;
}
else
strSql = "Create PROCEDURE #ImgeUpdate \n @RptDescription varchar(1000) \n as update Reports set RptDescription = @RptDescription where RptID = " + rptID;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
sqlCommStoreProcedue.CommandText = strSql;
sqlCon.Open();
sqlCommStoreProcedue.ExecuteNonQuery();
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
SqlCommand sqlCom = new SqlCommand();
sqlCom.Connection = sqlCon;
sqlCom.CommandType = CommandType.StoredProcedure;
sqlCom.CommandText = "#ImgeUpdate";
if (chk.Checked)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
if (filUL.HasFile)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int intImgSize = filUL.PostedFile.ContentLength;
Stream ImgStream = filUL.PostedFile.InputStream;
byte[] ImgContent = new byte[intImgSize];
int intStatus = ImgStream.Read(ImgContent, 0, intImgSize);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
SqlParameter prmImg = new SqlParameter("@RptImage", SqlDbType.Image);
prmImg.Value = ImgContent;
sqlCom.Parameters.Add(prmImg);
sqlCom.Parameters["@RptImage"].Direction = ParameterDirection.Input;
}
}
SqlParameter prmDes = new SqlParameter("@RptDescription", SqlDbType.VarChar, 1000);
prmDes.Value = txtDesp.Text.ToString().Trim();
sqlCom.Parameters.Add(prmDes);
sqlCom.Parameters["@RptDescription"].Direction = ParameterDirection.Input;
try
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
sqlCom.ExecuteNonQuery();
ClientScript.RegisterStartupScript(this.GetType(), "closeWin_Save", "<script>alert('Save This Record Succeed!');window.close();</script>");
}
catch (SqlException sqlE)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
ClientScript.RegisterStartupScript(this.GetType(), "Error_Msg", "<script>alert('Save This Record Failing:" + sqlE.Message + "');</script>");
}
finally
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
sqlCommStoreProcedue.Dispose();
sqlCom.Dispose();
sqlCon.Close();
}
存储过程的效率是比较高的。
转载于:https://www.cnblogs.com/lfzwenzhu/archive/2008/12/18/1357392.html