Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is my aspx.cs code for the "Application Form":

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace PrintersInkWebApplication
{
    public partial class Orders : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection
        ("server=HLCLITBIRRISH\\MSSQLSERVERAYB ;Initial Catalog=PrintersInk;
        User ID=asdfs;Password=2342453");

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //mangment
                SqlCommand cmd_mang = new SqlCommand
                ("Select Mangment_Name from Employee_Data", con);

                SqlDataAdapter da = new SqlDataAdapter(cmd_mang);

                DataSet ds = new DataSet();
                da.Fill(ds);
                drpdl_mang.DataTextField = 
                     ds.Tables[0].Columns["Mangment_Name"].ToString();
                drpdl_mang.DataSource = ds.Tables[0];
                drpdl_mang.DataBind();

                //department
                SqlCommand cmd_dep = new SqlCommand
                           ("Select L_nam3 from Employee_Data", con);

                SqlDataAdapter dad = new SqlDataAdapter(cmd_dep);

                DataSet dsd = new DataSet();
                dad.Fill(dsd);
                drpdl_dep.DataTextField = 
                      dsd.Tables[0].Columns["L_nam3"].ToString();
                drpdl_dep.DataSource = dsd.Tables[0];
                drpdl_dep.DataBind();

                //unit
                SqlCommand cmd_unt = new SqlCommand
                           ("Select L_nam4 from Employee_Data", con);

                SqlDataAdapter dau = new SqlDataAdapter(cmd_unt);

                DataSet dsu = new DataSet();
                dau.Fill(dsu);
                drpdl_unt.DataTextField = 
                      dsu.Tables[0].Columns["L_nam4"].ToString();
                drpdl_unt.DataSource = dsu.Tables[0];
                drpdl_unt.DataBind();

                //printertype
                SqlCommand cmd_pt1 = new SqlCommand
                   ("Select O_PrinterName from Printers_Table", con);

                SqlDataAdapter dp1 = new SqlDataAdapter(cmd_pt1);

                DataSet dsp1 = new DataSet();
                dp1.Fill(dsp1);
                drpdl_pt1.DataTextField = 
                  dsp1.Tables[0].Columns["O_PrinterName"].ToString();
                drpdl_pt1.DataSource = dsp1.Tables[0];
                drpdl_pt1.DataBind();

                SqlCommand cmd_pt2 = new SqlCommand
                   ("Select O_PrinterName from Printers_Table", con);

                SqlDataAdapter dp2 = new SqlDataAdapter(cmd_pt1);

                DataSet dsp2 = new DataSet();
                dp2.Fill(dsp2);
                drpdl_pt2.DataTextField = 
                  dsp2.Tables[0].Columns["O_PrinterName"].ToString();
                drpdl_pt2.DataSource = dsp2.Tables[0];
                drpdl_pt2.DataBind();

                SqlCommand cmd_pt3 = new SqlCommand
                   ("Select O_PrinterName from Printers_Table", con);

                SqlDataAdapter dp3 = new SqlDataAdapter(cmd_pt3);

                DataSet dsp3 = new DataSet();
                dp3.Fill(dsp3);
                drpdl_pt3.DataTextField = 
                  dsp3.Tables[0].Columns["O_PrinterName"].ToString();
                drpdl_pt3.DataSource = dsp3.Tables[0];
                drpdl_pt3.DataBind();

                SqlCommand cmd_pt4 = new SqlCommand
                   ("Select O_PrinterName from Printers_Table", con);

                SqlDataAdapter dp4 = new SqlDataAdapter(cmd_pt4);

                DataSet dsp4 = new DataSet();
                dp4.Fill(dsp4);
                drpdl_pt4.DataTextField = 
                  dsp4.Tables[0].Columns["O_PrinterName"].ToString();
                drpdl_pt4.DataSource = dsp4.Tables[0];
                drpdl_pt4.DataBind();

                SqlCommand cmd_pt5 = new SqlCommand
                   ("Select O_PrinterName from Printers_Table", con);

                SqlDataAdapter dp5 = new SqlDataAdapter(cmd_pt5);

                DataSet dsp5 = new DataSet();
                dp5.Fill(dsp5);
                drpdl_pt5.DataTextField = 
                  dsp5.Tables[0].Columns["O_PrinterName"].ToString();
                drpdl_pt5.DataSource = dsp5.Tables[0];
                drpdl_pt5.DataBind();
            }
        }

        protected void imgbtn_save_Click(object sender, ImageClickEventArgs e)
        {
            string cbx = "";
            string cbx2 = "";
            if (cb_printer.Checked) cbx += "طابعة";
              else 
             cbx += null;
            if (cb_ink.Checked) cbx2 += "حبر";
            else
                cbx2 += null;
//()

            //string rbl=
            string sql = "insert into Oreders_Table 
            values(@empname,@odate,@mang,@dep,@unt,@pcheck,
                   @purpose,@pcolor,@numpaper,@icheck,@pt1,@pt2,@pt3,
                   @pt4,@pt5,@nw1,@nw2,@nw3,@nw4,@nw5)";
            SqlCommand cmn_add_order = new SqlCommand(sql, con);

            cmn_add_order.Parameters.AddWithValue("@empname", txt_empname.Text);
            cmn_add_order.Parameters.AddWithValue("@odate", txt_date.Text);
            cmn_add_order.Parameters.AddWithValue
                          ("@mang", drpdl_mang.SelectedValue);
            cmn_add_order.Parameters.AddWithValue
                          ("@dep", drpdl_dep.SelectedValue);
            cmn_add_order.Parameters.AddWithValue
                          ("@unt", drpdl_unt.SelectedValue);
            cmn_add_order.Parameters.AddWithValue("@pcheck", cbx);
            cmn_add_order.Parameters.AddWithValue
                          ("@purpose", txt_purpose.Text);
            cmn_add_order.Parameters.AddWithValue
                  ("@pcolor", rbl_pcolor.SelectedItem.Text);
            cmn_add_order.Parameters.AddWithValue
                          ("@numpaper", txt_numpaper.Text);
            cmn_add_order.Parameters.AddWithValue("@icheck", cbx2);
            cmn_add_order.Parameters.AddWithValue
                          ("@pt1", drpdl_pt1.SelectedValue);
            cmn_add_order.Parameters.AddWithValue
                          ("@pt2", drpdl_pt2.SelectedValue);
            cmn_add_order.Parameters.AddWithValue
                          ("@pt3", drpdl_pt3.SelectedValue);
            cmn_add_order.Parameters.AddWithValue
                          ("@pt4", drpdl_pt4.SelectedValue);
            cmn_add_order.Parameters.AddWithValue
                          ("@pt5", drpdl_pt5.SelectedValue);
            cmn_add_order.Parameters.AddWithValue("@nw1", txt_nw1.Text);
            cmn_add_order.Parameters.AddWithValue("@nw2", txt_nw2.Text);
            cmn_add_order.Parameters.AddWithValue("@nw3", txt_nw3.Text);
            cmn_add_order.Parameters.AddWithValue("@nw4", txt_nw4.Text);
            cmn_add_order.Parameters.AddWithValue("@nw5", txt_nw5.Text);

            con.Open();
            cmn_add_order.ExecuteNonQuery();
            con.Close();
            lbl_message.Text = "done";
        }
    }
}


What I have tried:

All the solutions that I've found are how to send plain text.
Posted
Updated 23-Feb-22 10:11am
v8
Comments
Richard MacCutchan 16-Feb-22 4:57am    
You can either send it as an attachment in whatever format you want, or convert it to HTML in the main message.
Ansam Y. B. 16-Feb-22 7:11am    
ok... how to send it as an attachment?
if you can give me the way to.. or if you have any articles about this subject
Richard MacCutchan 16-Feb-22 7:59am    
That will depend on which class you are using to send the email.
Richard Deeming 17-Feb-22 12:13pm    
User ID=sa;Password=sa@sa123


1) I hope that isn't your real sa password that you've just posted to a public forum. If it is, change it immediately - and this time, chose a strong password that isn't on a "top N worst passwords" list!

2) A web application should never connect to SQL as the sa account. That is an unrestricted user which could be used to destroy your database, your server, or even your entire network. Instead, create a specific user for you application, and give it only the permissions required by your application.

3) Don't hard-code your connection strings; store them in the web.config file instead. Otherwise, you'll be cursing yourself when you come to deploy your application to a live server and need to go through every file to change the connection string to point to a different SQL instance.
Ansam Y. B. 23-Feb-22 3:37am    
Thanks for your notes.
I'm a beginner and I'm still learning

1 solution

"Plain text" solutions are fine if you want to embed the form data in your email: just surround it with the appropriate HTML code and it will almost certainly display as you wanted. HTML is just text with some tags which let the display software know how to display something.
So this HTML included in the body of your email:
HTML
<table><tr>Title</tr><tr><td>Row 1</td><td>Column 2</td></tr>
<tr><td>Another Row</td><td>Column 2</td></tr>
<tr><td>Final Row</td><td>Column 2</td></tr></table>
Will generate this when the user reads it:

Title

Row 1Column 2
Another RowColumn 2
Final RowColumn 2

And so on.

Alternatively as Richard has said, attach the data as a file in your (or your users) prefered format: Text, JSON, Excel, Word, XML, binary, ... whatever is most useful at the other end!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900