muhammad12 says:
protected
void
Save(
object
sender, EventArgs e)
{
DataTable dt = GetData();
dt.Columns.Add(
"Barcode"
,
typeof
(
byte
[]));
foreach
(DataRow dr
in
dt.Rows)
{
string
id = dr[
"id"
].ToString();
string
date = dr[
"Date"
].ToString();
string
name = dr[
"Name"
].ToString();
string
department = dr[
"Department"
].ToString();
string
address = dr[
"Address"
].ToString();
string
phonenumber = dr[
"PhoneNumber"
].ToString();
string
sendername = dr[
"SenderName"
].ToString();
string
dept = dr[
"Dept"
].ToString();
string
senderaddress = dr[
"SenderAddress"
].ToString();
string
mobile = dr[
"MobileNumber"
].ToString();
byte
[] bytes = GetBarcodeByte(id);
dr[
"Barcode"
] = bytes;
string
conString = ConfigurationManager.ConnectionStrings[
"dbcs"
].ConnectionString;
using
(SqlConnection con =
new
SqlConnection(conString))
{
using
(SqlCommand cmd =
new
SqlCommand(
"INSERT INTO UserDataTable (Date, Name, Department, Address, PhoneNumber, SenderName, Dept, SenderAddress, MobileNumber, ContentType, Data) VALUES(@Date, @Name, @Department, @Address, @PhoneNumber, @SenderName, @Dept, @SenderAddress, @MobileNumber, @ContentType, @Data)"
, con))
{
cmd.Parameters.AddWithValue(
"@Date"
, date);
cmd.Parameters.AddWithValue(
"@Name"
, name);
cmd.Parameters.AddWithValue(
"@Department"
, name);
cmd.Parameters.AddWithValue(
"@Address"
, name);
cmd.Parameters.AddWithValue(
"@PhoneNumber"
, name);
cmd.Parameters.AddWithValue(
"@SenderName"
, name);
cmd.Parameters.AddWithValue(
"@Dept"
, name);
cmd.Parameters.AddWithValue(
"@SenderAddress"
, name);
cmd.Parameters.AddWithValue(
"@MobileNumber"
, name);
cmd.Parameters.AddWithValue(
"@ContentType"
,
"image/png"
);
cmd.Parameters.AddWithValue(
"@Data"
, bytes);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
Session[
"Data"
] = dt;
Response.Redirect(
"~/printpage.aspx"
);
}
Replace above code with below.
protected void Save(object sender, EventArgs e)
{
DataTable dt = GetData();
dt.Columns.Add("Barcode", typeof(byte[]));
dt.Clear();
DataRow dr = dt.NewRow();
dr["Id"] = txtid.Text;
dr["Date"] = txtdate.Text;
dr["Name"] = txtName.Text;
dr["Department"] = txtdepartment.Text;
dr["Address"] = txtaddress.Text;
dr["PhoneNumber"] = txtphonenumber.Text;
dr["SenderName"] = txtsender.Text;
dr["Dept"] = txtdept.Text;
dr["SenderAddress"] = txtsenderaddress.Text;
dr["MobileNumber"] = txtmobilenumber.Text;
byte[] bytes = GetBarcodeByte(id);
dr["Barcode"] = bytes;
dt.Rows.Add(dr);
string conString = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO UserDataTable (Date, Name, Department, Address, PhoneNumber, SenderName, Dept, SenderAddress, MobileNumber, ContentType, Data) VALUES(@Date, @Name, @Department, @Address, @PhoneNumber, @SenderName, @Dept, @SenderAddress, @MobileNumber, @ContentType, @Data)", con))
{
cmd.Parameters.AddWithValue("@Date", txtdate.Text);
cmd.Parameters.AddWithValue("@Name", txtName.Text);
cmd.Parameters.AddWithValue("@Department", txtdepartment.Text);
cmd.Parameters.AddWithValue("@Address", txtaddress.Text);
cmd.Parameters.AddWithValue("@PhoneNumber", txtphonenumber.Text);
cmd.Parameters.AddWithValue("@SenderName", txtsender.Text);
cmd.Parameters.AddWithValue("@Dept", txtdept.Text);
cmd.Parameters.AddWithValue("@SenderAddress", txtsenderaddress.Text);
cmd.Parameters.AddWithValue("@MobileNumber", txtmobilenumber.Text);
cmd.Parameters.AddWithValue("@ContentType", "image/png");
cmd.Parameters.AddWithValue("@Data", bytes);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
Session["Data"] = dt;
Response.Redirect("~/printpage.aspx");
}