I am Continuoulsy getting error like
Error like what for?
Please post the complete error message and the line of code, where the error occurs.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class StudentAdmission : System.Web.UI.Page
{
public SqlConnection con { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
LoadRecord();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString); con.Open();
SqlCommand comm = new SqlCommand("Insert into Studentinfo (StudentID,StudentName,Address,Age,Contact) values('" + int.Parse(txtid.Text) + "','" + txtstdname.Text + "','" + ddladdress.SelectedValue + "','" + double.Parse(txtage.Text) + "','" + txtcontact.Text + "')", con);
comm.ExecuteNonQuery();
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('succesfully Inserted');", true);
con.Close();
LoadRecord();
}
void LoadRecord()
{
SqlCommand comm = new SqlCommand("selecct * from Studentinfo", con);
SqlDataAdapter d = new SqlDataAdapter(comm);
DataTable dt = new DataTable();
d.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
I am Continuoulsy getting error like
Error like what for?
Please post the complete error message and the line of code, where the error occurs.
You have a typo on this line
SqlCommand comm = new SqlCommand("selecct * from Studentinfo", con);
In addition, this is also wrong, you should use parameters and not string concatenation.
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString); con.Open();
SqlCommand comm = new SqlCommand("Insert into Studentinfo (StudentID,StudentName,Address,Age,Contact) values('" + int.Parse(txtid.Text) + "','" + txtstdname.Text + "','" + ddladdress.SelectedValue + "','" + double.Parse(txtage.Text) + "','" + txtcontact.Text + "')", con);
comm.ExecuteNonQuery();
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('succesfully Inserted');", true);
con.Close();
LoadRecord();
}