Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# insert from with bind array

using(var connection = new MySqlConnection("your connection string"))
{
    using(var command = new MySqlCommand("INSERT INTO programs (name, id) VALUES (?name, ?id)", connection))
    {
        var nameParameter = new MySqlParameter("name");
        var idParameter = new MySqlParameter("id");

        command.Parameters.Add(nameParameter);
        command.Parameters.Add(idParameter);

        connection.Open();

        for(int i = 0; i < name.Length; i++)
        {
             nameParameter.Value = name[i];
             idParameter.Value = id[i];

             command.ExecuteNonQuery();             
        }

        connection.Close(); //Dispose being called by the using should close connection, but it doesn't hurt to close it here/sooner either.         
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: make first 2 words upper case c# 
Csharp :: how to perform drop down when click on combobox in c# net 
Csharp :: hierachical table to c# class 
Csharp :: whining 
Csharp :: Zxing Xamarin use front Camera 
Csharp :: List foreach 
Csharp :: C# return dictionary string/integer from comparison of List and Array 
Csharp :: how to make dissapear an object in unity 
Csharp :: fetch post .net 
Csharp :: linqkit predicatebuilder or and nested combined predicates 
Csharp :: how to add onclick event dynamically in unity 
Csharp :: take the last 50 from array c# 
Csharp :: edit form item from class C# 
Csharp :: Filter list contents with predicate (anonymous method) 
Csharp :: Expression And Filter 
Csharp :: lambda not null c# 
Csharp :: #StopRape 
Csharp :: Min max to 01 
Csharp :: check if variable less than in f# 
Csharp :: c# md5 hash bouncycastle encypt decrypt with key 
Csharp :: MVC Razor check for postback 
Csharp :: c# one dimensional dictionary 
Csharp :: how do make internet 
Csharp :: c# find the smallest string in an array of strings 
Csharp :: Insert all data of a datagridview to database at once 
Csharp :: cshtml page title 
Csharp :: CS0176 
Csharp :: linq query languages 
Csharp :: how to take previous record in linq c# 
Csharp :: ArgumentOutOfRangeException when sorting a DataGridView using a custom IComparer 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =