romasha ali

romasha ali

  • NA
  • 94
  • 38.1k

Inserting Query

May 21 2013 5:39 PM
what happened to this code when i ran this code it did not insert values into my database table ...


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

public partial class course : System.Web.UI.Page

{   // string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
// SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

//     protected void Page_Load(object sender, EventArgs e)
//  {
// con.Open();
//  }
//  protected void Button1_Click(object sender, EventArgs e)
// {
// //SqlConnection con = new SqlConnection(connStr);
// SqlCommand cmd = new SqlCommand("insert into profile values('" + name.Text+ "','" + fname.Text+ "','" + ep.Text+ "','" + cls.Text+ "','" + semester.Text+ "')", con);

////con.Open();
// cmd.ExecuteNonQuery();
////cm.ExecuteNonQuery();
//// con.Close();
    
    SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        con.Open();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlCommand cmd = new SqlCommand("insert into profile(studentname,fathername,ep1) values('" +TextBox1.Text + "','" +TextBox2.Text+ "', '" +TextBox3.Text+ "')", con);
        cmd.ExecuteNonQuery();
        con.Close();
        Label1.Visible = true;
        Label1.Text = "Registered Successfully";
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3. Text = "";

        //string s1 = string.Empty;
        //foreach (ListItem item in this.checkbox.Items)
        //{
        //    if (item.Selected)
        //    {
        //        s1 = item.ToString();
        //        SqlCommand com = new SqlCommand("Insert into profile(courseId) values('" + s1 + "')", con);
        //        // con.Open();
        //        com.ExecuteNonQuery();
        //        con.Close();
        //    }
        //} Response.Write("Inserted Successfully");

    }

Answers (10)