Hi all..i have some trouble to insert data into 2 table.. i use asp.net with C# language..this is my table :
DOCUMENT
id_document
name
description
VERSI
Id_versi
Id_document
url_file
size
type
modifiedon
relationship of document and versi is one to many..
this is my code, but i cant store anything..
can u help me to correct my code, please??
protected void Button_Upload_Click(object sender, EventArgs e)
{
try
{
DMSDataAccess db = new DMSDataAccess();
DOCUMENT doc = new DOCUMENT();
VERSI versi = new VERSI();
doc.name = TextBox_Form_Judul.Text;
doc.description = TextBox_Form_Deskripsi.Text;
db.DMSDataContext.DOCUMENTs.InsertOnSubmit(doc);
db.DMSDataContext.SubmitChanges();
if (FileUpload1.HasFile)
{
string strFileName = FileUpload1.FileName.ToString();
string strExtension = Path.GetExtension(strFileName);
string strTimeStamp = DateTime.Now.ToString("yyyyMMdd-HHmmss.fff");
string strName = Path.GetFileNameWithoutExtension(strFileName);
strFileName = strName + "-" + strTimeStamp + strExtension;
this.FileUpload1.SaveAs(Server.MapPath(@"~\\Staf\\Uploads\\" + strFileName.ToString()));
Label_Upload_Response.Text = "Upload file berhasil!";
double size_file = FileUpload1.PostedFile.ContentLength;
string type_file = FileUpload1.PostedFile.ContentType;
versi.IdDocument = doc.IdDocument;
versi.UrlFile = "Uploads/" + strFileName;
versi.Size = size_file;
versi.Type = type_file;
versi.ModifiedOn = DateTime.Now;
db.DMSDataContext.VERSIs.InsertOnSubmit(versi);
db.DMSDataContext.SubmitChanges();
}
}
catch
{
}