how to read text file in c# and store in database console ap
i want to read text from text file and save text file data into my SQL database how can i do this any idea? i am new to the c# languange
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Biswa Pujarini MohapatraPosted Jan 31, 2014, 9:50 PM
hope it helps you, let me know if you need anything else
Nitin SontakkePosted Jan 10, 2018, 7:51 AM
Suresh ReddyPosted Jan 10, 2018, 7:46 AM
Ankita PatelPosted Mar 4, 2016, 3:50 PM
Ali AshiqPosted Feb 8, 2014, 3:46 AM
Ali AshiqPosted Feb 8, 2014, 2:19 AM
Biswa Pujarini MohapatraPosted Feb 6, 2014, 7:00 AM
Ali AshiqPosted Feb 6, 2014, 6:24 AM
Biswa Pujarini MohapatraPosted Feb 6, 2014, 5:22 AM
let me know if you found any issue
Ali AshiqPosted Feb 6, 2014, 5:14 AM
Biswa Pujarini MohapatraPosted Feb 6, 2014, 4:36 AM
Ali AshiqPosted Feb 6, 2014, 3:29 AM
Here is my new methods to get two methods one will return matched resturants based on product price entered by user and then user can select one resturant and it will display product details. When i debug my web services it will show nothing except empty xml
Biswa Pujarini MohapatraPosted Feb 5, 2014, 3:05 PM
Ali AshiqPosted Feb 5, 2014, 2:19 PM
Biswa Pujarini MohapatraPosted Feb 5, 2014, 7:58 AM
Ali AshiqPosted Feb 5, 2014, 6:42 AM
Biswa Pujarini MohapatraPosted Feb 5, 2014, 2:34 AM
here is your sql command
1) to get restaurant name
Select Rstname from ResturantNames R(nolock) join Resturantproducts rp
on r.rst_id = rp.rst_id where rp.price <='300'
2) to get product details based on Resturant name
Select rp.* from Resturantproducts Rp(nolock) join Resturantnames r
on r.rst_id = rp.rst_id where r.name <='Mcdonald'
Ali AshiqPosted Feb 4, 2014, 9:15 AM
Ali AshiqPosted Feb 3, 2014, 3:10 PM
Ali AshiqPosted Feb 3, 2014, 2:43 PM
SELECT * FROM RstProductDetails WHERE Product_Price <='300'
when i execute this query it will show all records which is less than or greater than 300. I am shocked about this, and Product_Price (nvarchar), because when we scrapped websites through scrapper code it will store automatically in the database ans the price format on different websites is e.g "Rs 600" or "Rs 1,300".
i have a price in both format "2000" or "2,000" so in which datatype i select for Product_price that will give me exact Product which is <=300
Biswa Pujarini MohapatraPosted Feb 2, 2014, 5:04 PM
Ali AshiqPosted Feb 2, 2014, 7:08 AM
Ali AshiqPosted Feb 2, 2014, 6:57 AM
now the scrapped text file is have only three fields i have attached text file as well.
I have a question how could we add RstID automatically please give me idea.
Biswa Pujarini MohapatraPosted Feb 1, 2014, 10:10 PM
I am not so clear about your requirement.
As per my understanding you are looking for two methods one will return matched resturants based on product price entered by user and then user can select one resturant and it will display product details. is it so, please confirm
Ali AshiqPosted Feb 1, 2014, 12:30 PM
Ali AshiqPosted Feb 1, 2014, 12:00 PM
Ali AshiqPosted Feb 1, 2014, 4:16 AM
Ali AshiqPosted Feb 1, 2014, 3:09 AM
Ali AshiqPosted Feb 1, 2014, 3:05 AM
let suppose 4/1000=250 and now 250 is , match in Product_Price Field in RstProductDetails, and select only Restaurant where 250 is matched. Next when a user select Restaurant e.g KFC and then KFC Products details is show.
Here is my [WebMethod]
VulpesPosted Jan 31, 2014, 5:30 PM
SqlCommand cmd = new SqlCommand("INSERT INTO Products(Product_Name, Product_Price, RstName) VALUES (@Product_Name, @Product_Price, @RstName)", con);
Ali AshiqPosted Jan 31, 2014, 1:34 PM
this error is showing!
Biswa Pujarini MohapatraPosted Jan 31, 2014, 3:13 AM
Please change your connection string and table accordingly
Ali AshiqPosted Jan 29, 2014, 7:03 AM
Here is my text file information, and i want to insert these information in my SQL Database, Having fileds Product_Name, Product_Price, RstName
and these information seprated by Comma Separated Value, and First color insert in Product_Name, and 280 insert in Product_Price and McDonald in RstName.
Biswa Pujarini MohapatraPosted Jan 28, 2014, 2:40 PM
class Test
{
public static void Main()
{
try
{
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
String line = sr.ReadToEnd();
Console.WriteLine(line);
}
}
catch (Exception e)
{
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
}
}
this is how you can read your data from textfile. Can you paste your data format in textfile how it is, so that i can give you the exact code
to insert into Db