TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Hazel Mahmud
1.4k
315
71.1k
Serialization problem
Oct 20 2018 10:07 PM
i have page which upload file to session state because it uses Mode="INPROC" in local PC.. when it is transfered to development server, it gives error as below because the development server use Mode="SQL SERVER"
how can i fix this error?.. below are my codes :
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data;
using
System.Data.SqlClient;
using
System.Configuration;
namespace
session.MOU_MOA
{
public
partial
class
AddDokumen : System.Web.UI.Page
{
SqlDataAdapter da =
new
SqlDataAdapter();
protected
void
Page_Load(
object
sender, EventArgs e)
{
//<%------------------------------------------------------- nanti buka balik upload5--%>
if
(Session[
"FileUploadPerjanjian"
] ==
null
&& FileUploadPerjanjian.HasFile)
{
Session[
"FileUploadPerjanjian"
] = FileUploadPerjanjian;
lblperjanjian.Text = FileUploadPerjanjian.FileName;
}
else
if
(Session[
"FileUploadPerjanjian"
] !=
null
&& (!FileUploadPerjanjian.HasFile))
{
FileUploadPerjanjian = (FileUpload)Session[
"FileUploadPerjanjian"
];
lblperjanjian.Text = FileUploadPerjanjian.FileName;
}
else
if
(FileUploadPerjanjian.HasFile)
{
Session[
"FileUploadPerjanjian"
] = FileUploadPerjanjian;
lblperjanjian.Text = FileUploadPerjanjian.FileName;
}
}
protected
void
ddlagensi_SelectedIndexChanged(
object
sender, EventArgs e)
{
string
ags_id = ddlagensi.SelectedValue;
BindAgensi(ags_id);
}
private
void
BindAgensi(
string
ags_id)
{
DataTable dt =
new
DataTable();
SqlDataAdapter adp =
new
SqlDataAdapter();
try
{
using
(SqlConnection moucon = ClassConn.GetMouCon())
{
moucon.Open();
SqlCommand com =
new
SqlCommand(
"mou_ret_agensi3"
, moucon);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue(
"@ags_id"
, SqlDbType.VarChar).Value = ags_id;
adp.SelectCommand = com;
adp.Fill(dt);
if
(dt.Rows.Count > 0)
{
lblagensiID.Text = dt.Rows[0][
"ags_id"
].ToString();
lbljenisAgensi.Text = dt.Rows[0][
"jen_ags"
].ToString();
lbljenisAgensiID.Text = dt.Rows[0][
"ags_jenis_id"
].ToString();
lblnegara.Text = dt.Rows[0][
"negara_desc"
].ToString();
lblnegeri.Text = dt.Rows[0][
"negeri_desc"
].ToString();
lblperingkat.Text = dt.Rows[0][
"negara_value"
].ToString();
}
moucon.Close();
}
}
catch
(Exception ex)
{
ex.Message.ToString();
}
finally
{
dt.Dispose();
adp.Dispose();
}
}
protected
void
btnSimpan_Click(
object
sender, EventArgs e)
{
Session[
"FileUploadPerjanjian"
] = FileUploadPerjanjian;
lblperjanjian.Text = FileUploadPerjanjian.FileName;
if
(FileUploadPerjanjian.HasFile)
{
String doc_name = FileUploadPerjanjian.FileName.Trim();
if
(doc_name.Substring(doc_name.LastIndexOf(
"."
)) ==
".pdf"
|| doc_name.Substring(doc_name.LastIndexOf(
"."
)) ==
".docx"
)
{
using
(SqlConnection moucon = ClassConn.GetMouCon())
{
moucon.Open();
SqlCommand cmd =
new
SqlCommand(
"mou_ins_FileUpload"
, moucon);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"@jan_id"
, lbljanid.Text);
cmd.Parameters.AddWithValue(
"@doc_name"
, lblperjanjian.Text);
cmd.Parameters.AddWithValue(
"@doc_file"
, FileUploadPerjanjian.FileBytes);
try
{
cmd.ExecuteNonQuery();
this
.lblUploadMsg.Visible =
true
;
this
.lblUploadMsg.Text =
"<font color=green>Upload dokumen berjaya.</font>"
;
}
catch
(Exception ex)
{
lblUploadMsg.Text = ex.Message;
}
finally
{
moucon.Close();
moucon.Dispose();
}
moucon.Close();
}
}
else
this
.lblUploadMsg.Text =
"Hanya .pdf dan .docx dokumen diterima!"
;
}
else
{
this
.lblUploadMsg.Visible =
true
;
this
.lblUploadMsg.Text =
"<font>Sila pilih dokumen untuk diupload!</font>"
;
}
using
(SqlConnection moucon = ClassConn.GetMouCon())
{
moucon.Open();
da.SelectCommand =
new
SqlCommand(
"SELECT doc_id FROM dokumen where doc_name='"
+ FileUploadPerjanjian.FileName +
"'"
, moucon);
string
doc_id = Convert.ToString(da.SelectCommand.ExecuteScalar());
lbldoc_id.Text = doc_id;
moucon.Close();
}
using
(SqlConnection moucon = ClassConn.GetMouCon())
{
moucon.Open();
SqlCommand com =
new
SqlCommand(
"mou_ins_perjanjian"
, moucon);
//creating SqlCommand object
com.CommandType = CommandType.StoredProcedure;
//here we declaring command type as stored Procedure
if
(txtKeterangan.Text ==
""
)
{
com.Parameters.AddWithValue(
"@jan_keterangan"
, ddlagensi.SelectedItem.Text);
}
else
{
com.Parameters.AddWithValue(
"@jan_keterangan"
, txtKeterangan.Text.ToString());
}
com.Parameters.AddWithValue(
"@jan_program"
, txtProgPengajian.Text.ToString());
if
(txtTarikhMohon.Text ==
""
)
{
com.Parameters.AddWithValue(
"@jan_apply_date"
,
"01/01/1900 12:00:00 AM"
);
}
else
{
DateTime oDate = Convert.ToDateTime(txtTarikhMohon.Text);
com.Parameters.AddWithValue(
"@jan_apply_date"
, oDate);
}
if
(txtTarikhSign.Text ==
""
)
{
com.Parameters.AddWithValue(
"@jan_date_sign"
,
"01/01/1900 12:00:00 AM"
);
}
else
{
DateTime oDate = Convert.ToDateTime(txtTarikhSign.Text);
com.Parameters.AddWithValue(
"@jan_date_sign"
, oDate);
}
com.Parameters.AddWithValue(
"@jan_due_date"
, txtTarikhTamat.Text.ToString());
if
(ddlTempoh.SelectedItem.Text ==
"--Select--"
)
{
com.Parameters.AddWithValue(
"@jan_tempoh"
,
""
);
}
else
{
com.Parameters.AddWithValue(
"@jan_tempoh"
, ddlTempoh.Text.ToString());
}
if
(txtDateJKMU.Text ==
""
)
{
com.Parameters.AddWithValue(
"@jan_jkmu_date"
,
"01/01/1900 12:00:00 AM"
);
}
else
{
DateTime oDate = Convert.ToDateTime(txtDateJKMU.Text);
com.Parameters.AddWithValue(
"@jan_jkmu_date"
, oDate);
}
if
(ddlkeputusanJKMU.SelectedItem.Value ==
"--Select--"
)
{
com.Parameters.AddWithValue(
"@jan_jkmu_result"
,
""
);
}
else
{
com.Parameters.AddWithValue(
"@jan_jkmu_result"
, ddlkeputusanJKMU.Text.ToString());
}
com.Parameters.AddWithValue(
"@jan_jkmu_ruj"
, txtRujJKMU.Text.ToString());
if
(txtTarikhJPU.Text ==
""
)
{
com.Parameters.AddWithValue(
"@jan_jpu_date"
,
"01/01/1900 12:00:00 AM"
);
}
else
{
DateTime oDate = Convert.ToDateTime(txtTarikhJPU.Text);
com.Parameters.AddWithValue(
"@jan_jpu_date"
, oDate);
}
if
(ddlkeputusanJPU.SelectedItem.Value ==
"--Select--"
)
{
com.Parameters.AddWithValue(
"@jan_jpu_result"
,
""
);
}
else
{
com.Parameters.AddWithValue(
"@jan_jpu_result"
, ddlkeputusanJPU.Text.ToString());
}
com.Parameters.AddWithValue(
"@jan_jpu_ruj"
, txtRujJPU.Text.ToString());
if
(txtTarikhLPU.Text ==
""
)
{
com.Parameters.AddWithValue(
"@jan_lpu_date"
,
"01/01/1900 12:00:00 AM"
);
}
else
{
DateTime oDate = Convert.ToDateTime(txtTarikhLPU.Text);
com.Parameters.AddWithValue(
"@jan_lpu_date"
, oDate);
}
if
(ddlkeputusanLPU.SelectedItem.Value ==
"--Select--"
)
{
com.Parameters.AddWithValue(
"@jan_lpu_result"
,
""
);
}
else
{
com.Parameters.AddWithValue(
"@jan_lpu_result"
, ddlkeputusanLPU.Text.ToString());
}
com.Parameters.AddWithValue(
"@jan_lpu_ruj"
, txtRujLPU.Text.ToString());
if
(ddlJabatan.SelectedItem.Value ==
"--Select--"
)
{
com.Parameters.AddWithValue(
"@jbt_id"
,
""
);
}
else
{
com.Parameters.AddWithValue(
"@jbt_id"
, ddlJabatan.Text.ToString());
}
com.Parameters.AddWithValue(
"@ags_id"
, lblagensiID.Text.ToString());
com.Parameters.AddWithValue(
"@jenis_id"
, ddlJenisDokumen.Text.ToString());
com.Parameters.AddWithValue(
"@jan_catatan"
, txtCatatan.Text.ToString());
com.Parameters.AddWithValue(
"@jan_aktiviti"
, txtAktiviti.Text.ToString());
com.Parameters.AddWithValue(
"@jan_contact_name"
, txtStaf.Text.ToString());
com.Parameters.AddWithValue(
"@jan_contact_no"
, txtcontactno.Text.ToString());
com.Parameters.AddWithValue(
"@doc_id"
, lbldoc_id.Text.ToString());
com.Parameters.AddWithValue(
"@stat_id"
, ddlStatusPerjanjian.Text.ToString());
com.ExecuteNonQuery();
moucon.Close();
}
using
(SqlConnection moucon = ClassConn.GetMouCon())
{
moucon.Open();
da.SelectCommand =
new
SqlCommand(
"SELECT jan_id FROM perjanjian where doc_id ='"
+ lbldoc_id.Text +
"'"
, moucon);
string
jan_id = Convert.ToString(da.SelectCommand.ExecuteScalar());
lbljanid.Text = jan_id;
moucon.Close();
}
using
(SqlConnection moucon = ClassConn.GetMouCon())
{
moucon.Open();
da.UpdateCommand =
new
SqlCommand(
"UPDATE dokumen SET jan_id = '"
+ lbljanid.Text +
"' where doc_id ='"
+ lbldoc_id.Text +
"'"
, moucon);
da.UpdateCommand.ExecuteNonQuery();
moucon.Close();
}
Response.Redirect(
"Search.aspx"
);
}
protected
void
chkOverwrite_CheckedChanged(
object
sender, EventArgs e)
{
if
(chkOverwrite.Checked ==
true
)
{
using
(SqlConnection moucon = ClassConn.GetMouCon())
{
moucon.Open();
da.DeleteCommand =
new
SqlCommand(
"DELETE FROM dokumen WHERE doc_name='"
+ lblperjanjian.Text +
"'"
, moucon);
moucon.Close();
}
}
}
protected
void
ddlJenisDokumen_SelectedIndexChanged(
object
sender, EventArgs e)
{
if
(ddlJenisDokumen.SelectedItem.Text !=
"MOA"
)
{
txtKeterangan.Enabled =
false
;
txtKeterangan.BackColor = System.Drawing.Color.LightGray;
}
else
{
txtKeterangan.Enabled =
true
;
txtKeterangan.BackColor = System.Drawing.Color.Empty;
}
}
protected
void
ddlkeputusanJKMU_SelectedIndexChanged(
object
sender, EventArgs e)
{
if
(ddlkeputusanJKMU.SelectedItem.Text ==
"Ditolak"
|| ddlkeputusanJKMU.SelectedItem.Text ==
"--Select--"
)
{
txtTarikhJPU.Enabled =
false
;
txtTarikhJPU.BackColor = System.Drawing.Color.LightGray;
txtRujJPU.Enabled =
false
;
txtRujJPU.BackColor = System.Drawing.Color.LightGray;
ddlkeputusanJPU.Enabled =
false
;
ddlkeputusanJPU.BackColor = System.Drawing.Color.LightGray;
txtTarikhLPU.Enabled =
false
;
txtTarikhLPU.BackColor = System.Drawing.Color.LightGray;
txtRujLPU.Enabled =
false
;
txtRujLPU.BackColor = System.Drawing.Color.LightGray;
ddlkeputusanLPU.Enabled =
false
;
ddlkeputusanLPU.BackColor = System.Drawing.Color.LightGray;
}
else
{
txtTarikhJPU.Enabled =
true
;
txtTarikhJPU.BackColor = System.Drawing.Color.Empty;
txtRujJPU.Enabled =
true
;
txtRujJPU.BackColor = System.Drawing.Color.Empty;
ddlkeputusanJPU.Enabled =
true
;
ddlkeputusanJPU.BackColor = System.Drawing.Color.Empty;
txtTarikhLPU.Enabled =
true
;
txtTarikhLPU.BackColor = System.Drawing.Color.Empty;
txtRujLPU.Enabled =
true
;
txtRujLPU.BackColor = System.Drawing.Color.Empty;
ddlkeputusanLPU.Enabled =
true
;
ddlkeputusanLPU.BackColor = System.Drawing.Color.Empty;
}
}
protected
void
ddlStatusPerjanjian_SelectedIndexChanged(
object
sender, EventArgs e)
{
if
(ddlStatusPerjanjian.SelectedItem.Text ==
"Permohonan Baru"
)
{
txtTarikhSign.Enabled =
false
;
txtTarikhTamat.Enabled =
false
;
ddlTempoh.Enabled =
false
;
txtDateJKMU.Enabled =
false
;
txtRujJKMU.Enabled =
false
;
ddlkeputusanJKMU.Enabled =
false
;
txtTarikhJPU.Enabled =
false
;
txtRujJPU.Enabled =
false
;
ddlkeputusanJPU.Enabled =
false
;
txtTarikhLPU.Enabled =
false
;
txtRujLPU.Enabled =
false
;
ddlkeputusanLPU.Enabled =
false
;
txtAktiviti.Enabled =
false
;
txtCatatan.Enabled =
false
;
}
else
{
txtTarikhSign.Enabled =
true
;
txtTarikhTamat.Enabled =
true
;
ddlTempoh.Enabled =
true
;
txtDateJKMU.Enabled =
true
;
txtRujJKMU.Enabled =
true
;
ddlkeputusanJKMU.Enabled =
true
;
txtTarikhJPU.Enabled =
true
;
txtRujJPU.Enabled =
true
;
ddlkeputusanJPU.Enabled =
true
;
txtTarikhLPU.Enabled =
true
;
txtRujLPU.Enabled =
true
;
ddlkeputusanLPU.Enabled =
true
;
txtAktiviti.Enabled =
true
;
txtCatatan.Enabled =
true
;
}
}
protected
void
ddlkeputusanJPU_SelectedIndexChanged(
object
sender, EventArgs e)
{
if
(ddlkeputusanJPU.SelectedItem.Text ==
"Ditolak"
|| ddlkeputusanJPU.SelectedItem.Text ==
"--Select--"
)
{
txtTarikhLPU.Enabled =
false
;
txtTarikhLPU.BackColor = System.Drawing.Color.LightGray;
txtRujLPU.Enabled =
false
;
txtRujLPU.BackColor = System.Drawing.Color.LightGray;
ddlkeputusanLPU.Enabled =
false
;
ddlkeputusanLPU.BackColor = System.Drawing.Color.LightGray;
}
else
{
txtTarikhLPU.Enabled =
true
;
txtTarikhLPU.BackColor = System.Drawing.Color.Empty;
txtRujLPU.Enabled =
true
;
txtRujLPU.BackColor = System.Drawing.Color.Empty;
ddlkeputusanLPU.Enabled =
true
;
ddlkeputusanLPU.BackColor = System.Drawing.Color.Empty;
}
}
}
}
Reply
Answers (
2
)
website wih asp net c#
how to fill a web form and save it as other web form in asp