 |
|
 |
If I am taking delimitor for the csv file as single quote (') then how hould I put it as delemitor in my connection string. When I am importing the file.
Thank you,
Regards,
Aleem.
S/W Engineer
Akebono Soft Technologies
aleem_abdul@akebonosoft.com.
|
|
|
|
 |
|
 |
Hello,
My problem is that i don't want to import the strings between some special characters, i want to import the whole text from a .txt or .doc file. How can i do that?
Thanks.
Sare
|
|
|
|
 |
|
 |
There are enough examples given in MSDN to do this. You may also get it on other sites. You need simple IO operation here. still I am giving you a sample code from MSDN:
The following code example shows a simple way to read text from a text file.
using System;
using System.IO;
class Test
{
public static void Main()
{
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
catch (Exception e)
{
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
}
}
|
|
|
|
 |
|
 |
I have a CSV file with 15 columns in it. I know the sample project was setup for just 2 columns. I am only getting 2 columns of data showing. If I edit the 14 in this line...for (int j = 1; j <= da.Tables["Stocks"].Columns.Count - 14; j++) to 13 I gain an additional column of data but the rows duplicate once. As I decrease the 14 one by one, each number I decrease by is how many duplicates of the rows I get. Can someone help me out on this?
// Now we will collect data from data table and insert it into database one by one
// Initially there will be no data in database so we will insert data in first two columns
// and after that we will update data in same row for remaining columns
// The logic is simple. 'i' represents rows while 'j' represents columns
cmd.Connection = con1;
cmd.CommandType = CommandType.Text;
cmd1.Connection = con1;
cmd1.CommandType = CommandType.Text;
con1.Open();
for (int i = 0; i <= da.Tables["Stocks"].Rows.Count - 1; i++)
{
for (int j = 1; j <= da.Tables["Stocks"].Columns.Count - 14; j++)
{
cmd.CommandText = "Insert into Test (srno, " + da.Tables["Stocks"].Columns[0].ColumnName.Trim() + ") values(" + (i + 1) + ",'" + da.Tables["Stocks"].Rows[i].ItemArray.GetValue(0) + "')";
// For UPDATE statement, in where clause you need some unique row
//identifier. We are using ‘srno’ in WHERE clause.
cmd1.CommandText = "Update Test set " + da.Tables["Stocks"].Columns[j].ColumnName.Trim() + " = '" + da.Tables["Stocks"].Rows[i].ItemArray.GetValue(j) + "' where srno =" + (i + 1);
cmd.ExecuteNonQuery();
cmd1.ExecuteNonQuery();
}
}
Thanks,
JMO
-- modified at 9:33 Monday 22nd January, 2007
|
|
|
|
 |
|
 |
Move the following lines before the inner loop:
cmd.CommandText = "Insert into Test (srno, " + da.Tables["Stocks"].Columns[0].ColumnName.Trim() + ") values(" + (i + 1) + ",'" + da.Tables["Stocks"].Rows[i].ItemArray.GetValue(0) + "')";
cmd.ExecuteNonQuery();
It was trying to insert 15 rows (i.e. the number of columns).
BTW: You should probably look at using a parametorized SQLCommand. If there are any single-quotes in your CSV data then it will cause an error in your current code.
Regards
Andy
|
|
|
|
 |
|
 |
Thanks for your quick answer, that did fix that particular problem.
How would I set a parameterized SQLCommand? My code is erroring out on line 436 because of a quotation mark.
This is what I have now.
sql_select = "select * from ["+ filetable +"]";
Thanks,
JMO
|
|
|
|
 |
|
 |
Hi,
This code Geeting all column Data Into DataBase.
cmd.Connection = con1;
cmd.CommandType = CommandType.Text;
cmd1.Connection = con1;
cmd1.CommandType = CommandType.Text;
con1.Open();
for (int i = 0; i <= da.Tables["Stocks"].Rows.Count - 1; i++)
{
for (int j = 1; j <= da.Tables["Stocks"].Columns.Count - 14; j++)
{
if(j==0){
cmd.CommandText = "Insert into Test (srno, " + da.Tables["Stocks"].Columns[0].ColumnName.Trim() + ") values(" + (i + 1) + ",'" + da.Tables["Stocks"].Rows[i].ItemArray.GetValue(0) + "')";
cmd.ExecuteNonQuery();
}
else {
// For UPDATE statement, in where clause you need some unique row
//identifier. We are using ‘srno’ in WHERE clause.
cmd1.CommandText = "Update Test set " + da.Tables["Stocks"].Columns[j].ColumnName.Trim() + " = '" + da.Tables["Stocks"].Rows[i].ItemArray.GetValue(j) + "' where srno =" + (i + 1);
cmd1.ExecuteNonQuery();
}
}
}
|
|
|
|
 |
|
 |
HI,
this is good code but when i m trying to open connection with odbc i m getting an error msg like "ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified". please solve my problem ....
thanks in advance
|
|
|
|
 |
|
 |
This is because, fupCsvFile.FileName will give u only the filename. Try using fupCsvFile.PostedFile.FileName where fupCsvFile is the nama of the FileUploader control .Now fupCsvFile.PostedFile.FileName will give u the filename with file path.
Pls try this.
Nishanth Nair
|
|
|
|
 |
|
 |
I solved this problem by changing the connection string
Driver={Microsoft Text Driver (*.txt;*.csv)};
to
Driver={Microsoft Text-Treiber (*.txt; *.csv)};
if you have a look in the BDE Administrator console in Control Panel, under the Configuration tab, you'll find the list of the drivers you can use. just pick the correct one
|
|
|
|
 |
|
 |
jadejonge wrote: solved this problem by changing the connection string
Driver={Microsoft Text Driver (*.txt;*.csv)};
to
Driver={Microsoft Text-Treiber (*.txt; *.csv)};
Note that ODBC driver names need to be specified exactly as they are named; I had exactly the same error as you and found that I was also missing a space after the semicolon in the extension list; ie you need:
Driver={Microsoft Text Driver (*.txt; *.csv)}; (right)
rather than:
Driver={Microsoft Text Driver (*.txt;*.csv)}; (wrong)
Hope this helps others!
Timshel Knoll-Miller
|
|
|
|
 |
|
 |
Hi,
Thank you so much for your program I used it and it works perfectly. The only doubt is that when I run DBI executable in order to generate the conString.txt file I get a warning message saying "Could not find a part of the path "D:\". I know you have mentioned that the .CSV file has to be in the D drive but is there a way to change the path from D drive to a C drive, I don't have a D drive in my PC all I have is a C drive.
I'll be looking forward to hear from you very soon....
Thanks in advance,
Sam Khanjar
Developer Engineer
|
|
|
|
 |
|
 |
Hi Mukund,
This is a nice app that I could learn from. Could you also please provide the connection string text file to the SQLServer?
Thanks,
Sekhar
Sekhar
|
|
|
|
 |
|
 |
Hi ..
It was really a nice work done by you. But there is a little problem with it.
my CSV file column names contains. dot "." i.e. First.Name and while import the csv to datatable these dots are converting into "#" so it becomes like First#Name.
Hope you can figure it out.
Regars / Xkaliber
|
|
|
|
 |
|
 |
Hi,
good work...but...
connstring.txt...
is not in project...
why??
Please...can i build this file...
Thnkx
Gvt
|
|
|
|
 |
|
 |
when i imported csv data in dataset, i have found the data which was changed.
this is my csv data:
001,001,2006-5-31,34,001,004,1200,1143,700_13
001,001,2006-5-31,34,002,003,1500,1429,700_13
001,002,2006-5-31,34,003,003,1500,1429,700_13
but the data in dataset is:
1,1,2006-5-31,34,1,4,1200,1143,700_13
1,1,2006-5-31,34,2,3,1500,1429,700_13
1,2,2006-5-31,34,3,3,1500,1429,700_13
can you tell me why? and how can make the data of dataset as the same as the data in csv?
thanks!
i like program
|
|
|
|
 |
|
 |
This is nice little program, however when i Try to import my CSV file into it, it seeems to import random junk characters.
This same file opens fine in microsoft excel with no problem except it has more than 256 columns, so will not open fully.
Anybody have an ideas on this ??
|
|
|
|
 |
|
 |
Hi friends
I am abdul basit. i have a problem when i open asp.net project its giving me some error.
Error is :- Visual Studio cannot creat or open the application because the web server on this computer is not running. Start the web server before proceeding.
another thing when i restart IIS that time its giving also an error
Error is :- The service Has not been started.
this iis problem accured when first time i started internet on my pc.
plz help me and my email ID is abasitt@hotmail.com
|
|
|
|
 |
|
 |
This dose not support unicode...IMO, this issue is might caused by Microst Text driver does not support unicode, right?
is there any workaround for this?
Thanx
<< >>
|
|
|
|
 |
|
 |
nice keep thw good work
AMH
Software Developer
LIFE'S SHORT. If you don't look around once in a while you might miss it
|
|
|
|
 |
|
 |
All the code work well, but when I try to import a line that contain a double quote the odbc doesn't import anythink from that character to the end of line for ex:
1!SOMETEXT!15 " TFT!SOMETEXT
import only
1!SOMETEXT!15
ArmCaf
|
|
|
|
 |
|
 |
Hi,
You cannot use double quotes in this approach. I have made this clear in introduction of this article. I am not sure whether this is limitation of this approach or any CSV file as such.
|
|
|
|
 |
|
 |
I read the introduction and You say: "But you cannot specify double quotes (") as a delimiter". I'm not use the double quote as delimiter, the delimiter is (!), but the double quote is present in the field ... 15" ... that I want import. You know a workaround to import the data as is?
ArmCaf
|
|
|
|
 |
|
 |
Hello All,
This is really a nice tool to import CSV/Text file within .NET application. I'm using this methodology and I'm facing one problem while Import. On some machines instead of separate columns in data table, whole line from CSV is imported in one single column. In other words no matter how many columns are there in CSV file separated by comman, it is imported as one single column in dataset/datatable. Is this something related to driver?
Can any one help finding the reason and solution for this problem?
Thanks
|
|
|
|
 |
|
 |
Hi Tushar
You Can Use Schema.ini file for tht..
---------Schema.ini---------------
[File Name With Extention]
ColNameHeader = False
Format=CSVDelimited
CharacterSet = ANSI
Col1=Column1 Text Width 10
Col2=Column2 Text Width 30
Lakhan Pal Garg
For Any problem You can Contact me at
lakhangarg@gmail.com
|
|
|
|
 |