.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

DataTable DataRow Value Assumed to be Number

Posted By:      Posted Date: October 28, 2010    Points: 0   Category :Windows Application

My app reads in a .CSV file and parses it using the dAdapter.Fill(dTable) method.

This works fine and I can see the data in rows in the DataTable.

One of the fields in the .CSV file is "Customer Number".  When this value is put into the DataTable it is automatically added as a number type field.

When I try to read the DataRow value from that DataColumn I get an error because it is not a string type.


foreach (DataRow dr in myTable.Rows)






curItem.Item["CustNumber"] = <strong>dr["Customer Number"];</strong>





I have tried converting it to string and to int32 but nothing seems to work.

How do I convert it to a string?


View Complete Post

More Related Resource Links

who to load DataRow to DataTable



Who can I copy data from DataRow[] to DataTable....

DataRow[] TempDataRowFilter;



DataTable TempFilterTable = new DataTable();
TempFilterTable.LoadDataRow(TempDataRowFilter, true);

It is error why ?         

Transferring of DataTable Vs its List for a WCF?


I am trying to see if returning a DataTable containing 5000 records would be faster if I return instead a List<DataRow> collection from the WCF method. May be the List<DataRow> will have a smaller payload that that of original DataTable when sent via WCF ?



Returning a DataTable as List in WCF with WsHttpBinding

  • Would it be better in terms of payload, if I return a datatable as a List<DataRow> from a WCF method? I have WsHtppBinding for my WCF. I am expecting the datatable to contain 5,000 to 10,000 records.
  • Also, how can I test the difference in payload sizes when returning a DataTable Vs List<DataRow>?


How to bind GridView and DropDownList controls using DataTable object

In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.

DataTable - Load from IDataReader - CreateDataReader - ReadXml WriteXml - Free ADO.NET Tutorials

The DataTable in ADO.NET 2.0 has been seriously beefed up and I absolutely love it. Not everything we consume deals with multiple resultsets and requires the ever popular DataSet. With the cool new features in the ADO.NET 2.0 DataTable, we can get many of the cool features in the DataSet without all the extra baggage and memory footprint particular to multiple resultsets.

Load DataTable from IDataReader

Convert English to Arabic number without changing any regional settings in .net

Well, most applications that I worked with was multilingual that supports English UI and Arabic UI.

And one of the major issue that we have faced is displaying Arabic numbers without the need of changing the regional settings of the PC.

So the code below will help you to display Arabic number without changing any regional settings.

dynamically adding sql server columns based on number of files in fileuploader


I want to create a new table to sql database at runtime.  The column names would be "Name", "Date", "Event".  I would also like to have one more column name "Image" but the problem is that since the amount of images will vary, I want the application to count the amount of files in the Multiple fileuploader and then add a image column to the table for the respected amount of files. 

For example if i am uploading 3 files in the multiple fileuploader, the names should be "Name", "Date", "Event", "Image1", "image2", Image3"

I also would like that table name to be name dynamically from the textbox Name when the user enters the information.


I have the following code to make a new table, but I dont know how to name the fields at runtime like previously asked please help!!!


Dim objConn As New SqlConnection("Server=<servername>;uid=<userid>;pwd=<password>;database=master")


Embeb a variable number of videos


I need to provide some alternate content for my non-Flash users.

I have a directory of video files that is scanned using the DirectoryInfo() function, and I want to use the results to embed all files ending in ".mov" in QuickTime players on a web form.

How would you approach this? Right now I am using the count on the array of videos to determine how many times to repeat the embed code.  But this seems inelegant.

Is there a way to have a single QuickTime player.ascx control that gets duplicated according to the number of videos available for display?

Article commenting by line number


I'm wondering what's the best way to approach an online article system that allows users to comment by clicking on the line they are commenting about? Essentially the same way Adobe Acrobat works with comments where you can click anywhere and the text is saved for that location.

I'm assuming a mix of jQuery would be the crux of the interface. The system would need to save comments so that when another user logs in, they will also see the other comments but they can´t edit them - only add their own.

Any suggestions would be great.

The number of members in the conceptual type ... does not match with the number of members on the ob



I've added a scalar property to an entity and now ASP.NET Dynamic Data scaffolding throws this error:

The number of members in the conceptual type 'TrainingModel.Users' does not match with the number of members on the object side type 'TrainingModel.Users'. Make sure the number of members are the same.

This happens at the following line in global.asax:
model.RegisterContext(typeof(TrainingModel.TrainingEntities), new ContextConfiguration() { ScaffoldAllTables = true });

Please help!

Datatable in session


I am creating a simple shopping cart using a datatable that is passed into a session object.  I have a small mini cart that displays the total number of items in the cart as well as the running total - this is displayed in a web control.  When the web control starts up I run a try/catch to see if the session object exists, if it doesn't I create the datatable for the cart and store it in the session.  I then have a datalist control that contains all the information for my products including an "add to cart" button.  When the page loads everything looks fine.  If I click on an "add to cart" button nothing happens to the session information.  If I click on it again, the session information updates - displaying only one item is in the cart and then counts up correctly there after.  Additionally, after adding an item, if I select a different item in the list, the same issue occurs.  I am not sure why this is happeing, if anyone can give me an idea I would appreciate it. 

holding datatable value using session



iam insert record using datable in gridivew,iam using  session to hold the record,

there is any other way to hold the record in datable.


        DataRow row;
        row = dtempty.NewRow();
        row["ratetypeid"] = ddlratetype.SelectedValue;
        row["ratedesc"] = ddlratetype.SelectedItem.Text;
        row["slabs"] = ddlslabs.SelectedValue;   

huge number of data from database ... so how to minimize load time


Hi ...

I have used the above method to configure my crystal report ...

Its working fine , But i have huge number of data in database ....

So , it take long time to load the report ...

So , i have decided to show only the last 50 records inserted into the database , not all the 500 records to be loaded every time.

Plz help me with this issue  ...


Also , Plz explain me abt index legend in crystal report.

datarow data insertion error


this is the code which i am using and what i want means when i==0 first record should bind to datatable and when i==1 2nd record should bind to datatable. that means when i==1 1st and 2nd record should be present in datatable  Please see the code below


when i am binding 2nd record to datatable 1st record is getting deleted and recently inserted value is getting inserted please tell me how to resolvie this


datatable dt11=new datatable();
DataRow row11=null;

if (i == 0)
row11 = dt11.NewRow();

row11["qid"] = qnumber;

row11["question"] = question;
row11["useranswer"] = correctans;
row11["flag"] = answerstatus;


if (i == 1)

qnumber =ds5.Tables[0].Rows[i][0].ToString();
question =ds5.Tables[0].Rows[i][1].ToString();

row11 = dt11.NewRow();

removing item from datatable


hi to all ..thanks in advance


I have Two datatables dtA,dtB ,both contains column name is "FiledName" I need to remove item

from dtA when same row data exists in dtB.  please tell me how to do it

dtA    dtB   

 A        A

 B        F

 C        C

 D        Z

I want o/p like this







Bulk Copy From Datatable To SQL Server Table


 I have read the data of a excle file and captured the data into the dataset to a datatable, now that data is to be inserted into a SQL Server table using bulk copy option. I am using -

 public bool BulkEnterData(DataTable dt, string tblName)
        SqlBulkCopy bulk = new SqlBulkCopy(con);
        bulk.DestinationTableName = tblName;

        return true;

ERROR Getting-
A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - The pipe has been ended.) 

How to resolve the above problem or any other solution is available.


While Importing Excel 2007 file to Datatable - headerrow problem


Hi there,


I am trying to simply extract an excel data from an uploaded file an put it into a datatable. In this case the excel file has 3 rows but when I fill the datatable I only see row count of 2.

I tried changing HDR:NO; to HDR:YES and vice versa, but no luck. 

What am I doing wrong? (Note: the excel file cannot have a  headerrow)


string connstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pFilePath + ";Extended Properties=\"Excel 12.0;IMEX=1;HDR:NO;\"";
            OleDbConnection conn = new OleDbConnection(connstr);
            DataTable dtTables = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
            string strTablename = dtTables.Rows[0]["TABLE_NAME"].ToString();
            string strSQL = "SELECT * FROM [" + strTablename + "]";

            OleDbCommand cmd = new OleDbCommand(strSQL, conn);

            DataTable dt = new DataTable();
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            //At this point row count=2 which doesn't make sense




ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend