Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Insert all data of a datagridview to database at once

string StrQuery;
try
{
    using (SqlConnection conn = new SqlConnection(ConnString))
    {
        using (SqlCommand comm = new SqlCommand())
        {
            comm.Connection = conn;
            conn.Open();
            for(int i=0; i< dataGridView1.Rows.Count;i++)
            {
                StrQuery= @"INSERT INTO tableName VALUES (" 
                    + dataGridView1.Rows[i].Cells["ColumnName"].Text+", " 
                    + dataGridView1.Rows[i].Cells["ColumnName"].Text+");";
                comm.CommandText = StrQuery;
                comm.ExecuteNonQuery();
            }
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: two question marks together mean in C# 
Csharp :: c# cosmos db add items into container 
Csharp :: google script get font color 
Csharp :: missing integer c# 
Csharp :: my object is falling unity 
Csharp :: What is the best way to lock cache in asp.net? 
Csharp :: simplified if statement c# 
Csharp :: unity customize hierarchy window 
Csharp :: c# words return first 20 items of array 
Csharp :: small index c# 
Csharp :: f sharp functions calling each other 
Csharp :: file.deletealltext 
Csharp :: c# access control from another thread 
Csharp :: unfreeze position in unity 
Csharp :: c# generate random key with specified length 
Csharp :: using == is inefficient unity 
Csharp :: How to convert output of HttpClient PostAsJsonAsync() into user defined list of object 
Csharp :: flutter failed asertion 
Csharp :: nunjucks if variable exists 
Csharp :: auto paly a video control in mvc c# 
Csharp :: matric multiplication 
Csharp :: asp.net render control to string 
Csharp :: Unity PlayOneShoot Audio 
Csharp :: how can i only show just a part of alist in datagridview in c# 
Csharp :: how to make projectile track and go to specified enemy in unity 
Csharp :: return value of a mocked value will be as the input c# 
Csharp :: set data annotation in model c# 
Csharp :: c# nuint 
Csharp :: unity control physics of multiple simulation 
Csharp :: obs mfplat.dll 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =