سلام بر برنامه نویسان عزیز ایران زمین 😉 در این پست کد ذخیره داده های پایگاه داده sql server در فایل متنی در #C را آماده کردم. امیدوارم که این کد برای شما مفید باشد.
کد ذخیره داده های پایگاه داده sql server در فایل متنی در #C :
''class RetrieveText
{
static string textFile = null;
static char[] textChars = null;
static SqlConnection conn = null;
static SqlCommand cmd = null;
static SqlDataReader dr = null;
public RetrieveText()
{
conn = new SqlConnection(@"data source = .\sqlexpress;integrated security = true;initial catalog = tempdb;");
// Create command
cmd = new SqlCommand(@"select textfile,textdata from texttable", conn);
// Open connection
conn.Open();
// Create data reader
dr = cmd.ExecuteReader();
}
public static bool GetRow()
{
long textSize;
int bufferSize = 100;
long charsRead;
textChars = new Char[bufferSize];
if (dr.Read())
{
// Get file name
textFile = dr.GetString(0);
Console.WriteLine("------ start of file:");
Console.WriteLine(textFile);
textSize = dr.GetChars(1, 0, null, 0, 0);
Console.WriteLine("--- size of text: {0} characters -----",
textSize);
Console.WriteLine("--- first 100 characters in text -----");
charsRead = dr.GetChars(1, 0, textChars, 0, 100);
Console.WriteLine(new String(textChars));
Console.WriteLine("--- last 100 characters in text -----");
charsRead = dr.GetChars(1, textSize - 100, textChars, 0, 100);
Console.WriteLine(new String(textChars));
return true;
}
else
{
return false;
}
}
public static void endRetrieval()
{
// Close the reader and the connection.
dr.Close();
conn.Close();
}
static void Main()
{
try
{
while (GetRow() == true)
{
{
static string textFile = null;
static char[] textChars = null;
static SqlConnection conn = null;
static SqlCommand cmd = null;
static SqlDataReader dr = null;
public RetrieveText()
{
conn = new SqlConnection(@"data source = .\sqlexpress;integrated security = true;initial catalog = tempdb;");
// Create command
cmd = new SqlCommand(@"select textfile,textdata from texttable", conn);
// Open connection
conn.Open();
// Create data reader
dr = cmd.ExecuteReader();
}
public static bool GetRow()
{
long textSize;
int bufferSize = 100;
long charsRead;
textChars = new Char[bufferSize];
if (dr.Read())
{
// Get file name
textFile = dr.GetString(0);
Console.WriteLine("------ start of file:");
Console.WriteLine(textFile);
textSize = dr.GetChars(1, 0, null, 0, 0);
Console.WriteLine("--- size of text: {0} characters -----",
textSize);
Console.WriteLine("--- first 100 characters in text -----");
charsRead = dr.GetChars(1, 0, textChars, 0, 100);
Console.WriteLine(new String(textChars));
Console.WriteLine("--- last 100 characters in text -----");
charsRead = dr.GetChars(1, textSize - 100, textChars, 0, 100);
Console.WriteLine(new String(textChars));
return true;
}
else
{
return false;
}
}
public static void endRetrieval()
{
// Close the reader and the connection.
dr.Close();
conn.Close();
}
static void Main()
{
try
{
while (GetRow() == true)
{