资源预览内容
第1页 / 共34页
第2页 / 共34页
第3页 / 共34页
第4页 / 共34页
第5页 / 共34页
第6页 / 共34页
第7页 / 共34页
第8页 / 共34页
第9页 / 共34页
第10页 / 共34页
亲,该文档总共34页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
程序代码:下面的代码实现向SQLServer数据库添加图片和文字的功能。首先,在SQL查询分析器中执行下面的语句,以创建表和存储过程。DropTablePersonGoCreateTablePerson(PersonIDIntIdentity,PersonEmailVarchar(255),PersonNameVarchar(255),PersonSexChar(1),PersonDOBDateTime,PersonImageImage,PersonImageTypeVarchar(255)DropProcsp_person_ispGoCreateProcsp_person_ispPersonEmailVarchar(255),PersonNameVarchar(255),PersonSexChar(1),PersonDOBDateTime,PersonImageImage,PersonImageTypeVarchar(255)AsBeginInsertintoPerson(PersonEmail,PersonName,PersonSex,PersonDOB,PersonImage,PersonImageType)Values(PersonEmail,PersonName,PersonSex,PersonDOB,PersonImage,PersonImageType)EndGo下面就是完整的代码,拷贝即可运行:向SQLServer插入图片PublicSubAddPerson(senderAsObject,eAsEventArgs)DimintImageSizeAsInt64DimstrImageTypeAsStringDimImageStreamAsStream获得图片的大小intImageSize=PersonImage.PostedFile.ContentLength获得图片类型strImageType=PersonImage.PostedFile.ContentType读取图片ImageStream=PersonImage.PostedFile.InputStreamDimImageContent(intImageSize)AsByteDimintStatusAsIntegerintStatus=ImageStream.Read(ImageContent,0,intImageSize)创建Connection和Command对象DimstrCnnAsString=DataSource=.;InitialCatalog=mxh;UserId=sa;Password=;DimmyConnectionAsNewSqlConnection(strCnn)DimmyCommandAsNewSqlCommand(sp_person_isp,myConnection)使用存储过程myCommand.CommandType=CommandType.StoredProcedure向存储过程添加参数DimprmEmailAsNewSqlParameter(PersonEmail,SqlDbType.VarChar,255)prmEmail.Value=txtPersonEmail.TextmyCommand.Parameters.Add(prmEmail)DimprmNameAsNewSqlParameter(PersonName,SqlDbType.VarChar,255)prmName.Value=txtPersonName.TextmyCommand.Parameters.Add(prmName)DimprmSexAsNewSqlParameter(PersonSex,SqlDbType.Char,1)IfsexMale.CheckedThenprmSex.Value=MElseprmSex.Value=FEndIfmyCommand.Parameters.Add(prmSex)DimprmPersonDOBAsNewSqlParameter(PersonDOB,SqlDbType.DateTime)prmPersonDOB.Value=txtPersonDob.TextmyCommand.Parameters.Add(prmPersonDOB)DimprmPersonImageAsNewSqlParameter(PersonImage,SqlDbType.Image)prmPersonImage.Value=ImageContentmyCommand.Parameters.Add(prmPersonImage)DimprmPersonImageTypeAsNewSqlParameter(PersonImageType,SqlDbType.VarChar,255)prmPersonImageType.Value=strImageTypemyCommand.Parameters.Add(prmPersonImageType)TrymyConnection.Open()myCommand.ExecuteNonQuery()myConnection.Close()Response.Write(添加成功!)CatchSQLexcAsSqlExceptionResponse.Write(添加失败,原因:&SQLexc.ToString()EndTryEndSub
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号