Computer Science, asked by jayarvind96, 1 month ago

Program to store multiple integers in a binary file and read,display it on screen in sql​
reply fast plz

Answers

Answered by harshitakawa80
0

Answer:

hi good night have nice dreams

Answered by anjumanyasmin
0

From the given question the correct answer is:

public static void InsertFileintoSqlDatabase()

{

   string filePath = @"C:\sample.txt";

 

   using (SqlConnection sqlconnection = new SqlConnection(@"Data Source=.SQLExpress;  

Initial Catalog=MorganDB; Integrated Security=SSPI;"))

   {

       sqlconnection.Open();

 

       // create table if not exists  

       string createTableQuery = @"Create Table [MyTable](ID int, [FileData] varbinary(max))";

       SqlCommand command = new SqlCommand(createTableQuery, sqlconnection);

       command.ExecuteNonQuery();

 

       // Converts text file(.txt) into byte[]

       byte[] fileData = File.ReadAllBytes(filePath);

 

       string insertQuery = @"Insert Into [MyTable] (ID,[FileData]) Values(1,@FileData)";

 

       // Insert text file Value into Sql Table by SqlParameter

       SqlCommand insertCommand = new SqlCommand(insertQuery, sqlconnection);

       SqlParameter sqlParam = insertCommand.Parameters.AddWithValue("@FileData", fileData);

       sqlParam.DbType = DbType.Binary;

       insertCommand.ExecuteNonQuery();

   }

}

Similar questions