05-03-2012, 05:48 PM
وعليكم السلام ورحمة الله وبركاته
كنت استخدم الأداة bcp (مرفقة من SQL Serve) بشيء مثل:
عدلت عليه ليعمل عندك، إذا حصل خلل أعلمني
بالتوفيق.
كنت استخدم الأداة bcp (مرفقة من SQL Serve) بشيء مثل:
PHP كود :
function ExecuteCmd(CmdLine: string; ShowConsole: Boolean): Boolean;
const
flags: array [Boolean] of Integer = (SW_SHOWNORMAL, SW_HIDE);
var
cmdBuffer: array [0..MAX_PATH] of Char;
begin
GetEnvironmentVariable('COMSPEC', cmdBuffer, SizeOf(cmdBuffer));
StrCat(cmdBuffer, ' /C ');
StrPCopy(StrEnd(cmdBuffer), CmdLine);
Result := ShellExecute(Application.Handle, 'open', 'cmd', cmdBuffer, nil, flags[ShowConsole]) > 32;
end;
procedure BulkCmd(IsExport: Boolean);
function GetValue(ItemName: String): Variant;
begin
Result := DM.Cnt.Properties.Item[ItemName].Value;
end;
function PromptFile(var Dir, Title: String; Save: Boolean): Boolean;
begin
Result := BrowseForFile(Dir, 'Data file|*.dat', '*.dat', Title, '.', Save);
end;
var
sDir, Action, ServerSource, UserName: string;
begin
ServerSource := 'localhost\sqlexpress';
UserName := 'sa';
Password := 'P@ssw0rd';
TableName := 'YourTable';
if IsExport then begin
Action := 'Export...';
if not PromptFile(sDir, Action, True) then Exit;
if ExecuteCmd('bcp YourDatabase.dbo.'+TableName+' out "'+sDir+'" -n -S'+ServerSource+' -U'+UserName+' -P'+ Password) then
if FileExists(sDir) then
ShowMessage('File exported successfully.');
end else
try
Action := 'Import...';
if not PromptFile(sDir, Action, False) then Exit;
YourDataSet.Close;
try
YourADOConnection.Execute('BULK INSERT '+TableName+' FROM '+QuotedStr(sDir)+' WITH (DATAFILETYPE=''native''); ');
except
ShowMessage('Cannot import this file!');
end;
finally
YourDataSet.Open;
end;
end;
بالتوفيق.
اللهم احقن دماء المسلمين، لا تنسوهم بالدعاء...

