TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
romasha ali
NA
94
38.3k
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");
}
Reply
Answers (
10
)
how to use Templates in visual studio
asp.net connectivity with sql server 2008