Database Reference
In-Depth Information
{
cmd.CommandText = @"insert into TextTable
values (@textfile, @textdata)";
cmd.Parameters.Add("@textfile", SqlDbType.NVarChar, 30);
cmd.Parameters.Add("@textdata", SqlDbType.Text, 1000000);
}
private void ExecuteInsertTextFile(string textFile)
{
string textData = GetTextFile(textFile);
cmd.Parameters["@textfile"].Value = textFile;
cmd.Parameters["@textdata"].Value = textData;
ExecuteCommand(cmd.CommandText);
}
private string GetTextFile(string textFile)
{
string textBytes = null;
txtLoadText.AppendText("Loading File: " + textFile);
FileStream fs = new FileStream(textFile, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
textBytes = sr.ReadToEnd();
txtLoadText.AppendText("TextBytes has length" + textBytes.Length + " bytes.\n");
return textBytes;
}
6. To set the LoadText form as the start-up form, modify the Program.cs
statement.
Application.Run(new DisplayImages());
to appear as
Application.Run(new LoadText());
Build the project, and run it by pressing Ctrl+F5. You should see the results in
Figure 17-7.
Figure 17-7. Loading a text file into a table
 
Search WWH ::




Custom Search