Visual Studio, c#, SQL 2005 server. I"m trying to match the .dbml table data type with my .cs file. The goal is to allow an image to load to the database. So far it is not working. The issue seems to be related to the file type for the FileContent column. I have tried several different variations, but none have worked.
<Column Name="FileName" Type="System.String" DbType="NVarChar(100)" CanBeNull="true" />
<Column Name="FileType" Type="System.String" DbType="NVarChar(100)" CanBeNull="true" />
<Column Name="FileSize" Type="System.int32" DbType="int" CanBeNull="true" />
<Column Name="FileContent" Type="System.Data.Linq.Binary" DbType="varbinary(MAX)" CanBeNull="true" />
SQL Server Columns
Applicant_PK(PK,int,notnull)
FileName(nvarchar(100),null)
FileType(nvarchar(100),null)
FileSize(int,null)
FileContent(varbinary(max),null)
void CreatePreApplication()
{
Pre_Application = new PreApplication();
Pre_Application.FileName = Path.GetFileName(ctrFile.PostedFile.FileName);
Pre_Application.FileType = ctrFile.PostedFile.ContentType;
Pre_Application.FileSize = ctrFile.PostedFile.ContentLength;
byte[] fileContent = new byte[ctrFile.PostedFile.ContentLength];
ctrFile.PostedFile.InputStream.Read(fileContent, 0, ctrFile.PostedFile.ContentLength);
Pre_Application.FileContent = fileContent;
public class PreApplication
{ public int DatabaseId { get; set; } public String FileName { get; set; } public String FileType { get; set; } public int FileSize { get; set; } public byte[] FileContent { get; set; } public PreApplication()
{
PreApplicationsDataContext db =
new PreApplicationsDataContext(
"Data Source=THESQLSERVER;Initial Catalog=THECONNECTIONSTRING;Integrated Security=True");
tblPreApplication preApp = new tblPreApplication();
preApp.FileName = FileName;
preApp.FileType = FileType;
preApp.FileSize = FileSize;
preApp.FileContent = (byte[])FileContent;
try
{
db.tblPreApplications.InsertOnSubmit(preApp);
db.SubmitChanges();
DatabaseId = preApp.Applicant_PK;
return preApp.Applicant_PK;
}
catch
{
DatabaseId = 0;
return 0;
}
}
Thanks for looking at this. I am a novice at programming, so if you ask me a question, please keep this in mind.