Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my code

C#
protected void EMPLOYEERECORD_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            if (e.CommandName.Equals("ADD"))
            {
                DropDownList drpDepartment = (DropDownList)EMPLOYEERECORD.FooterRow.FindControl("drpDepartment");
                DropDownList DropDownList1 = (DropDownList)EMPLOYEERECORD.FooterRow.FindControl("DropDownList1");
                DropDownList drpCategory = (DropDownList)EMPLOYEERECORD.FooterRow.FindControl("drpCategory");
                TextBox txtAddRemarks = (TextBox)EMPLOYEERECORD.FooterRow.FindControl("txtAddRemarks");
                DropDownList drpStatus = (DropDownList)EMPLOYEERECORD.FooterRow.FindControl("drpStatus");


                DatabaseModule.SQcon.Open();
                string cmdstr = "insert into dbo.RecordEmployee (DATE_REPORTED, EMPLOYEE_NAME, DEPARTMENT, CATEGORY, REMARKS, TIME_IN,  TIME_OUT, EMP_STATUS) values(@dReported, @empname,@department,@category,@remarks,@tIN, @tOUT, @status)";
                SqlCommand cmd = new SqlCommand(cmdstr, DatabaseModule.SQcon);
                cmd.Parameters.AddWithValue("@dReported", DateTime.Now.ToString());
                cmd.Parameters.AddWithValue("@empname", DropDownList1.SelectedValue.ToString());
                cmd.Parameters.AddWithValue("@department", drpDepartment.SelectedValue.ToString());
                cmd.Parameters.AddWithValue("@category",drpCategory.SelectedValue.ToString());
                cmd.Parameters.AddWithValue("@remarks", txtAddRemarks.Text);
                cmd.Parameters.AddWithValue("@tIN", DateTime.Now.ToString());
                cmd.Parameters.AddWithValue("@tOut", "");
                cmd.Parameters.AddWithValue("@status", drpStatus.SelectedValue.ToString());
                cmd.ExecuteNonQuery();
                DatabaseModule.SQcon.Close();
                BindData();
            }  
        }



and here is my database table:

C#
create table dbo.RecordEmployee (DATE_REPORTED datetime primary key, EMPLOYEE_NAME varchar(50) NOT NULL,
                           DEPARTMENT varchar(40) NOT NULL,
                           CATEGORY varchar(20)NOT NULL, REMARKS varchar(100), TIME_IN datetime NOT NULL,
                           TIME_OUT datetime, EMP_STATUS varchar (20) NOT NULL)


how ever I keep on getting an exception, help please
Posted

This exception occurs when the entered data cannot be accommodated in one or more table column's. You need to verify the input using the break point. If you sql profiler installed then you could capture the query and then figure which column is causing the overflow. All the best.
 
Share this answer
 
Check the table structure for the RecordEmployee table. I think you'll find that the length of one or more fields is NOT big enough to hold the data you are trying to insert. For example, if the CATEGORY field is a varchar(20) field, and you try to put 21+ characters in to it, you will get this error.
for further reference :
http://www.aspdotnet-suresh.com/2012/09/sql-string-or-binary-data-would-be.html[^]
 
Share this answer
 
Please check yours data type length.




its not match properly..................


may be insert field heaving more length as you define in database or vice versa.....
 
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