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
Hil Isabelle
NA
9
1.9k
How can I insert data into a table using c#?
Jun 4 2020 1:52 PM
Hello everyone!
I've got a simple table 'Table' in a simple database 'Database1' with 2 rows (Id,Chemin) and I'm trying to insert data into my table but the opening of the connection to the database doesn't work (con.Open()). Can someone tell me why and help me please ? The code is below :
SqlConnection con =
new
SqlConnection(@
"Data Source=.\SQLEXPRESS;Initial Catalog=Database1;Integrated Security=True"
);
SqlCommand cmd =
new
SqlCommand(
"sp_insert"
, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"@Chemin"
, textBox1.Text);
//cmd.Parameters.AddWithValue("@email", textBox2.Text);
con.Open();
int
i = cmd.ExecuteNonQuery();
con.Close();
Reply
Answers (
4
)
Connection_Dropped in IIS
Row delete from database or Viewstate/Datatable