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
Ankit Rathore
NA
74
0
Insert values into database from ASP.NET page
Apr 14 2010 1:13 AM
Hi Guys,
Here I am facing a problem to insert values into database.
In my database already 2 rows is there, but now I wanted to put from asp.net page.
but at last when I give the value it will take automatically first record only,
and give error like "Primary Key can not be duplicate........"
In my code I am doing like that.............
Please help me what can I do ..............?
My Code is .......
try
{
if (Page.IsPostBack)
{
string InsertString = "Insert into Emp" + "(ID, Name, Designation, TempAddress, PermanentAddress, Salary, Contact)" +
"values('" + txtEmpId.Text + "','" + txtName.Text + "','" + txtDesignation.Text + "','" + txtPAddress.Text + "','" + txtTaddress.Text + "','" + txtSalary.Text + "','" + txtContact.Text + "')";
if (txtEmpId.Text != "" && txtName.Text != "" && txtDesignation.Text != "" && txtPAddress.Text != "" && txtTaddress.Text != "" && txtSalary.Text != "" && txtContact.Text != "")
{
SqlCommand command = new SqlCommand(InsertString, objcConnect.con);
objcConnect.dAdapEmp.InsertCommand = command;
objcConnect.dAdapEmp.InsertCommand.ExecuteNonQuery();
//command.ExecuteNonQuery();
MessageBox.Show("Value Inserted");
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Reply
Answers (
5
)
gridview with C#
how i get list of files in a folder and create new files