Home > Net > Questions about the file import SQL server database, senior counsel, please. Thank you
Questions about the file import SQL server database, senior counsel, please. Thank you
Time:09-24
Find a code for several days and Microsoft help, still can't find want processing method, using BULK insert import file is all direct import and must be determined format and table format corresponding I want import column according to the requirement of data, I see OPENROWSET, but did not understand, I do not know whether accord with I need (show just a little trouble understanding people thank you) Want to write a winfrom program, the selected file path, set up import column is the file which columns, can not choose not to import, more sets of data (such as file with three group id in one line, the name (name1 id1, id2, name2, id3, name3) data table only id, the name that I need to set up into three groups,) Like the image below, Find the following code, but I am stupid not understand , go to https://www.cnblogs.com/superlee/archive/2010/01/12/1645292.html The code below
string fPath=this. FName. PostedFile. The FileName;//get to import a text file String extName=fPath. Substring (fPath LastIndexOf (". ") + 1);//get file extensions SqlConnection con=new SqlConnection (" server=. The database=pubs; Uid=sa; The PWD=;" );//database connection object Con. The Open (); String mystring="Provider=Microsoft. Jet. The OLEDB. 4.0; The Data Source='" + fPath + "'; Extended Properties=8.0 "Excel; OleDbConnection CNNXLS=new OleDbConnection (mystring); OleDbDataAdapter myDa=new OleDbDataAdapter (" select * from [Sheet1 $] ", CNNXLS); The DataSet myDs=new DataSet (); MyDa. The Fill (myDs); If (myDs. Tables [0]. Rows. Count & gt; 0) { String strSql=""; String CnnString="Provider=SQLOLEDB; The database=pubs; Server=. Uid=sa; The PWD="; OleDbConnection conn=new OleDbConnection (CnnString); Conn. The Open (); OleDbCommand myCmd=null; for(int i=0; i{ StrSql="insert into txtInsert (id, name) values ("; StrSql +=myDs. Tables [0]. Rows [I] ItemArray [0]. The ToString () + ", ""; StrSql +=myDs. Tables [0]. Rows [I] ItemArray [1]. The ToString () + "");" MyCmd=new OleDbCommand (strSql, conn); Try { MyCmd. ExecuteNonQuery (); Response. Write (" & lt; Script language=javascript& gt; Alert (' data import is successful! ') & lt;/script>" ); } The catch (OleDbException err) { Response. Write (" error importing the database: "+ err. ToString ()); break; } } Conn. Close ();
If you have any elder passing by, please tell, grateful
CodePudding user response:
Above written by Delphi, no source, so can't
CodePudding user response:
The problem of import, and in the process you use ADO.NET nothing difference between
Does you read the data in the DataTable, then Insert into the database, ADO.NET usage is the same
Is don't want to say anything, you need to read the data from the file in Don't know what you from file to import, Excel? TXT?