April 27, 2011

How to save an text file into a database

byte[] bytes = File.ReadAllBytes(@"D:\Temp\myTextFile.txt");
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myColumn1) VALUES (@C1)", con))
        {
        com.Parameters.AddWithValue("@C1", bytes);
        com.ExecuteNonQuery();
        }
    }

No comments:

Post a Comment