Hello... I am Continuoulsy getting error like , i am unable to solve , please anybody help me

Vampire666 20 Reputation points
2023-05-10T05:46:03.33+00:00
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();

    }
}
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,521 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,051 questions
0 comments No comments
{count} votes

Accepted answer
  1. Olaf Helper 42,381 Reputation points
    2023-05-10T05:53:22.2333333+00:00

    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.


1 additional answer

Sort by: Most helpful
  1. Naomi 7,361 Reputation points
    2023-05-10T13:46:05.9+00:00

    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();
          
    
        }
    
    
    0 comments No comments