Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi guys,

I need some help and advice.

I had create the web data entry for user. Once user login, the name of user will appear in the data entry.

After the user entry all the data and submit, all the data are display in the database but without the user name.

The End user named as Staff, I plan to once user login and the name appeared in the data entry page, once they key in, it will auto pump into database and shown who had key in the data.

I using the Detailsview as my display in the page.

Please advice.

Please refer to my below code:

C#
namespace WebPortal
{
    public partial class DataEntry : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button7_Click(object sender, EventArgs e)
        {
            string connectionString = "Data Source=.\\SQLEXPRESS;"
            + "AttachDbFilename=\"C:\\Users\\KLSIT\\Documents\\Visual Studio 2008\\Projects\\WebPortal\\WebPortal\\App_Data\\emaildata.mdf\";"
            + "Integrated Security=True;"
            + "Connect Timeout=30;"
            + "User Instance=True";

            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectionString);

            System.Data.SqlClient.SqlCommand cmd = conn.CreateCommand();

            String FullName;
            String FirstName;
            String LastName;

            cmd.Parameters.Add("Type", SqlDbType.NVarChar);
            cmd.Parameters["Type"].Value = this.DropDownList2.Text;

            cmd.Parameters.Add("Title", SqlDbType.NVarChar);
            cmd.Parameters["Title"].Value = this.DropDownList1.Text;

            cmd.Parameters.Add("FirstName", SqlDbType.NVarChar);
            cmd.Parameters["FirstName"].Value = this.TextBox1.Text;

            cmd.Parameters.Add("LastName", SqlDbType.NVarChar);
            cmd.Parameters["LastName"].Value = this.TextBox2.Text;

            cmd.Parameters.Add("Fullname", SqlDbType.NVarChar);
            cmd.Parameters["Fullname"].Value = this.TextBox1.Text + "" + this.TextBox2.Text;

            cmd.Parameters.Add("Email", SqlDbType.NVarChar);
            cmd.Parameters["Email"].Value = this.TextBox3.Text;

            cmd.Parameters.Add("Job_Title", SqlDbType.NVarChar);
            cmd.Parameters["Job_Title"].Value = this.TextBox4.Text;

            cmd.Parameters.Add("Company", SqlDbType.NVarChar);
            cmd.Parameters["Company"].Value = this.TextBox5.Text;         

            cmd.Parameters.Add("Mobile_Phone", SqlDbType.NVarChar);
            cmd.Parameters["Mobile_Phone"].Value = this.TextBox6.Text;

            cmd.Parameters.Add("Office_Phone", SqlDbType.NVarChar);
            cmd.Parameters["Office_Phone"].Value = this.TextBox7.Text;

            cmd.Parameters.AddWithValue("Staff", SqlDbType.NVarChar);
            cmd.Parameters["Staff"].Value = this.DetailsView2.DataItemIndex;

                                
            FirstName = TextBox1.Text;
            LastName = TextBox2.Text;
            FullName = LastName + " " + FirstName;

            cmd.CommandText = "INSERT INTO [Customer] ([Type], [Title], [Firstname], [Lastname], [Fullname], [Company], [Email], [Mobile_Phone], [Office_Phone], [Job_Title], [Staff]) VALUES (@Type, @Title, @Firstname, @Lastname, @Fullname, @Company, @Email, @Mobile_Phone, @Office_Phone, @Job_Title, @Staff)";
         

            conn.Open();

            int numberOfRows = cmd.ExecuteNonQuery();

            conn.Close();

            Response.Redirect("Homepage.aspx");
Posted
Updated 16-Apr-15 0:21am
v2
Comments
Sinisa Hajnal 16-Apr-15 7:02am    
So, which field ends up empty? There is no user name here, do you mean First name?

May I suggest you rename your textboxes so the names make sense?
VandrenSKL 16-Apr-15 11:52am    
this line:

cmd.Parameters.AddWithValue("Staff";, SqlDbType.NVarChar);
cmd.Parameters["Staff"].Value = this.DetailsView2.DataItemIndex;

Others field able to goes into database after user key in the textbox.

For the detailsview, it will display the username from Staff table. How to make it insert into Customer table?

thank you
Anil_Kumar_India 16-Apr-15 12:03pm    
What is value in cmd.Parameters["Staff"].Value? This can be debug before ExecuteNonQuery
VandrenSKL 16-Apr-15 12:11pm    
Hi bro,

the value in the cmd.Parameters["Staff"] is the name of the user.

It will display on the data entry page after login. I want make sure that whoever key in the data, we can able to know whose key in and both are different table.

thank you
Sinisa Hajnal 17-Apr-15 2:36am    
This cannot be right. You're telling us what the field is supposed to hold, but you're putting DataINDEX (i.e. a number) into it.

Set a breakpoint on the line and check the values.

1 solution

Hey guys,

I had use another term and another way to represent it, I'm using label. The problem had solved.

Anyway thank you for you all and time, appreciate your help.
 
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