This Way
HTML:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtId" runat="server" />
<br />
<asp:TextBox ID="txtName" runat="server" />
<br />
<asp:TextBox ID="txtCity" runat="server" />
<br />
<asp:TextBox ID="txtState" runat="server" />
<br />
<asp:TextBox ID="txtSchool" runat="server" />
<br />
<asp:TextBox ID="txtSSC" runat="server" />
<br />
<asp:TextBox ID="txtHSC" runat="server" />
<br />
<asp:TextBox ID="txtUniversity" runat="server" />
<br />
<asp:Button Text="Save" OnClick="Save" runat="server" />
</div>
</form>
C#:
protected void Save(object sender, EventArgs e)
{
string id = this.txtId.Text == string.Empty ? "" : this.txtId.Text + ",";
string name = this.txtName.Text == string.Empty ? "" : this.txtName.Text + ",";
string city = this.txtCity.Text == string.Empty ? "" : this.txtCity.Text + ",";
string state = this.txtState.Text == string.Empty ? "" : this.txtState.Text + ",";
string school = this.txtSchool.Text == string.Empty ? "" : this.txtSchool.Text + ",";
string ssc = this.txtSSC.Text == string.Empty ? "" : this.txtSSC.Text + ",";
string hsc = this.txtHSC.Text == string.Empty ? "" : this.txtHSC.Text + ",";
// as University is the last TextBox then dont add , in the end
string university = this.txtUniversity.Text == string.Empty ? "" : this.txtUniversity.Text;
string final = id + name + city + state + school + ssc + hsc + university;
string output = final.Remove(final.Length - 1);
string constr = ConfigurationManager.ConnectionStrings["ConString2"].ConnectionString;
using (SqlConnection _cn = new SqlConnection(constr))
{
using (SqlCommand _cmd = new SqlCommand("INSERT INTO Description VALUES(@Value)", _cn))
{
using (SqlDataAdapter da = new SqlDataAdapter(_cmd))
{
_cn.Open();
_cmd.Parameters.AddWithValue("@Value", output);
_cmd.ExecuteNonQuery();
}
}
}
}
Thank You.