my table is
CREATE TABLE [dbo].[section](
[pk] [int] IDENTITY(1,1) NOT NULL,
[sectionid] [varchar](3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[sectionname] [varchar](80) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
my code to insert is
protected void bsu_Click(object sender, EventArgs e)
{
string str = "insert into section (sectionid,sectionname) values('" + txsi.Text.ToUpper();
str += "','" + txsn.Text;
str += "')";
gdv.Insert(str);
Label5.Text = "Section Is saved";
Label5.ForeColor = System.Drawing.Color.DarkGreen;
}
my class file is
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
/// Summary description for Marvel
/// </summary>
public class Marvel
{
string s = ConfigurationManager.AppSettings["s"].ToString();
SqlConnection cn = new SqlConnection();
SqlCommand cd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
public Marvel()
{
//
// TODO: Add constructor logic here
//
}
public void con()
{
try
{
if (cn.State == ConnectionState.Open)
{
cn = new SqlConnection(s);
cn.Close();
}
else
{
cn = new SqlConnection(s);
cn.Open();
}
}
catch (Exception e)
{
throw e;
}
finally
{
}
}
public void Insert(string qry)
{
try
{
con();
cd = new SqlCommand(qry, cn);
cd.ExecuteNonQuery();
}
catch (Exception e)
{
throw e;
}
finally
{
}
}
public DataSet GETDS(string qry)
{
try
{
con();
cd = new SqlCommand(qry, cn);
da = new SqlDataAdapter(cd);
da.Fill(ds);
return ds;
}
catch (Exception e)
{
throw e;
}
finally
{
cn.Close();
}
}
}
my error is
Server Error in '/bramandam site' Application.
String or binary data would be truncated.
The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: String or binary data would be truncated.
The statement has been terminated.
Source Error:
Line 63: catch (Exception e)
Line 64: {
Line 65: throw e;
Line 66: }
Line 67: finally
Source File: d:\jquery themes\bramandam site\App_Code\Marvel.cs Line: 65
Stack Trace:
[SqlException (0x80131904): String or binary data would be truncated.
The statement has been terminated.]
Marvel.Insert(String qry) in d:\jquery themes\bramandam site\App_Code\Marvel.cs:65
Section.bsu_Click(Object sender, EventArgs e) in d:\jquery themes\bramandam site\Section.aspx.cs:107
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Version Information: Microsoft .NET Framework Version:2.0.50727.4984; ASP.NET Version:2.0.50727.4971