In my aspx page I have a HTML inputfile type which allows user to browse for a spreadsheet.Once the user choses the file to upload I want to read the content of the spreadsheet and store the content into mysql database table. I am using the following code to read the content of the uploaded file and convert it into a datatable in order into insert it into database table.
if (filMyFile.PostedFile != null) { // Get a reference to PostedFile object HttpPostedFile myFile = filMyFile.PostedFile; // Get size of uploaded file int nFileLen = myFile.ContentLength; // make sure the size of the file is > 0 if (nFileLen > 0) { // Allocate a buffer for reading of the file byte[] myData = new byte[nFileLen]; // Read uploaded file from the Stream myFile.InputStream.Read(myData, 0, nFileLen);...................................
Every morning we send out an email with a text file attached. This is a manual process so I am automating it.I am using an internal mail web service. Its last two parameters are a byte array which is the file contents and a string which is the file name. I passed (...gbytes, "test.txt") and the only thing wrong with it is text.txt is XML. I want it to be text (csv is fine because there is actually four columns that come from a datatable).So I am assuming what's making it XML is this code:
Code: System.IO.MemoryStream stream = new System.IO.MemoryStream(); System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); formatter.Serialize(stream, ds.Tables[0]); gbytes = stream.GetBuffer();
I am trying to search the Internet for how to convert a datatable to a byte array, but I can't find how to have it be text instead of XML. Also, another parameter our WS takes is a flag to say if it's XML, and I am setting this to false.
If I am passed a datatable and I cant change the column structure..is there anyway to set an existing column to a Primary key so I can easily Find() the row I am looking for?
I have the following code reading in my xml file and sorting it by ID:
Dim ds As New DataSet ds.ReadXml(Server.MapPath("/posts.xml")) Dim dv As New DataView(ds.Tables(0)) dv.Sort = "id desc"
The only problem is that it isn't sorting it numerically (it's sorting it alphabetically 1, 10, 11, 2, 24, 3, 4...). It appears as though I have to convert that column into integers, but I haven't been able to figure out an efficient way to do that.
im ds As New DataSet ds.ReadXml(Server.MapPath("/App_Data/posts.xml")) 'ds.Tables(0).Columns(0).DataType = TypeOf(Decimal) Dim dv As New DataView(ds.Tables(0)) 'dv.Sort = "date"
I have a datalist in which i want to do away with -- change to data recieved into an array list.
Goal: This is a working code. Instead of setting the datasource (TABLE) for the DataList -- I want to set the data table to an array list
Dim xUserAccess As New User() xUserAccess.UserAccess(txtEmployeeID.Text) If xUserAccess.errorFlag Then lblErrorMsg.Text = xUserAccess.ErrorMessage Else DDLUserAccess.DataSource = xUserAccess.UserData -- Change to an array list DDLUserAccess.DataBind() End if
i need to convert from string to integer, i tried in all ways but no luck.... here is my code
[Code]....
here in checkdDoorID integer value is available, but i can't convert to string. i tried ctype,parse but nothing worked out. i need the value in integer so that i can stored in DB as primary key.
I need to convert a timespan into an integer. I have two dates that I am subtracting one from the other, returning a value in days. I then need to perform some arithmatical functions on that value but I cant figure out how.
protected void Page_Load(object sender, EventArgs e) { string imageUrl = Request.QueryString["img"]; int imageHeight = Request.QueryString["h"]; int imageWidth = Request.QueryString["w"];
[code]...
when i run it this error occur...An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0029: Cannot implicitly convert type 'string' to 'int'Source Error:
Line 21: string imageUrl = Request.QueryString["img"]; Line 22: Line 23: int imageHeight = Request.QueryString["h"]; Line 24: int imageWidth = Request.QueryString["w"]; Line 25:
i think i should convert strin to int but i dont know how i can do it.
I want to convert Label text into Integer datatype. I tried by giving Convert.Int32(Label1.Text) and int.Parse(Label1.Text) but I couldn't do Type casting . I am getting error at runtime. I searched in web I couldn't get the solution.
I am doing GridView Sorting without ObjectDataSource. For this requirement I need to convert DataTable to DataView, I know I can do that in VS 2008 but How can I do this in VS 2005.
i have an string data array which contains data like this
5~kiran 2~ram 1~arun 6~rohan
now a method returns an value like string [] data public string [] names()
{ return data.Toarray() } public class Person { public string Name { get; set; } public int Age { get; set; } ) List<Person> persons = new List<Person>(); string [] names =names();
now i need to copy all the data from an string array to an list<person> and finally bind to grid view
I want to retrieve and store(in an array) all the row values of a particular column in a gridview..i.e,if I have gridview with columns col1,col2 and col3, I want to retrieve rows of col1 by specifying col1..And,store all the rows in an array
i'm trying to sort a datatable using the typical select method*. The problem comes because the field is string defined but it's containing integer values.
With sql the problem will be solved just using something like:
select * from table order by to_number(field);
but of course it's not working properly with the method commented above (select method).
Possible Duplicate: Convert.ToInt32() a string with Commas i have a value in the label as: 12,000 and i wish to convert it into an integer like 12000 (use it for comparison) i tried int k = convert.toint32("12,000"); this does not work.