本文介绍了如何从DataAccessLayer调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为SmartVote.cs的DataAccessLayer(Class),但我没有使用它。这是我的代码
我在表单后面编码AddPicture.aspx
I have a DataAccessLayer (Class) called SmartVote.cs but i didn't use it. here is my code
that i coded behind the form AddPicture.aspx
// Read the file and convert it to Byte Array
string filePath = FileUpload2.PostedFile.FileName;
string filename = Path.GetFileName(filePath);
string ext = Path.GetExtension(filename);
string contenttype = String.Empty;
//Set the contenttype based on File Extension
switch (ext)
{
case ".doc":
contenttype = "application/vnd.ms-word";
break;
case ".docx":
contenttype = "application/vnd.ms-word";
break;
case ".pdf":
contenttype = "application/vnd.ms-word";
break;
}
if (contenttype != String.Empty)
{
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
//insert the file into database
string strQuery = "insert into PARTY(Party_Manifesto)" +
" values (@Party_Manifesto)";
SqlCommand cmd = new SqlCommand(strQuery);
//cmd.Parameters.Add("@Candidate_Image", SqlDbType.VarChar).Value = filename;
//cmd.Parameters.Add("@ContentType", SqlDbType.VarChar).Value
// = contenttype;
cmd.Parameters.Add("@Party_Manifesto", SqlDbType.Binary).Value = bytes;
InsertUpdateData(cmd);
lblmsg.ForeColor = System.Drawing.Color.Green;
lblmsg.Text = "File Uploaded Successfully";
}
else
{
lblmsg.ForeColor = System.Drawing.Color.Red;
lblmsg.Text = "File format not recognised." +
" Upload document/pdf/doc/docs formats";
}
请帮助
-SA
Please help
-SA
推荐答案
这篇关于如何从DataAccessLayer调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!