C# insert into database

using(var connection = new SqlConnection("connectionString"))
{
    connection.Open();
    var sql = "INSERT INTO Main(FirstName, SecondName) VALUES(@FirstName, @SecondName)";
    using(var cmd = new SqlCommand(sql, connection))
    {
        cmd.Parameters.AddWithValue("@FirstName", txFirstName.Text);
        cmd.Parameters.AddWithValue("@SecondName", txSecondName.Text);

        cmd.ExecuteNonQuery();
    }
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
c# how to insert into database oled using statement c# for insert in sql insert data into sql in c# c# insert database best way to insert data into sql table c# insert data into database using c# how to insert data in database from c# insert into database from c# insert into access database c# c# sql command insert insert data in sql using c# c# insert sql sql add to database c# insert statement in c# using sql command c# insert into sql server c# how to insert data into sql table insert value to sql in c# how many ways data insert in database in c# how many way data insert in database in c# insert data to database c# sql to C# insert into insert data into sql database in asp.net c# how to insert to sql in c# how to Insert data from the database in c# c# how to insert into database into other table c# how to insert into database how to instert into a database in c# sql statement to inster into a database in c# C# function for insert to database c# insert into database table c# how to insert data into database c# database insert data how to insert int into database using c#@ how to insert into sql table with c# c# sql insert into table how to insert into sql table using c# asp.net insert into sql database c# insert sql c# insert sql statement c# c# insert into mysql database c# insert into sql c# insert into sql table c# insert into database asp.net c# insert into sql database insert into sql c# how to insert data from c# to sql server c# insert into sql database c# insert into database mdf insert into database C# how to insert values into table in sql using c# how to insert data into database using c# insert data c# sql server insert data in sql server using asp.net c# sql isertion language C# desktop insert to sql table c# add input into sql database from c# get user data and put it into database using c sharp insert into c#
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source