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

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

Datatable and minLength restriction

Posted By:      Posted Date: October 01, 2010    Points: 0   Category :ASP.Net

Hi, i want to define an element which cannot be empty or with a minimum length , i was trying with datatable to insert the minLegth restriction

but it rejects it and accepts only the maxLength restriction, are there any way to resolve this?

I was thinking of regular expressions with facets but i have the same problem, datatable rejects it.

In my applications now i only read the schema and then write it to a file to see how does datatable sees the schema.

The xsd i load in the datatable is this:


<?xml version="1.0" standalone="yes"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="tabella" msdata:UseCurrentLocale="true">
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="tabella">

View Complete Post

More Related Resource Links

IP Address Blocking or Restriction in SQL Server

"is it possible to block connections to SQL Server based on IP address". As far as now there is no official way in SQL Server to block the connections in SQL Server based on IP address. However this can be done from the OS end, we have the following three options available, refer HERE for more.

.RRAS IP Filter

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

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;   

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




Conversion of List to DataTable and ViceVersa


hi ,

           Iam having a requirement where I wil get datatable or Dataview from the DataAccessLayer I need to convert them into GanaricList of entites and ViceVersa from GenericList to Datatable or DataView.

             I tried it but I cant. Can anybody help me out.

Data Points: DataSet and DataTable in ADO.NET 2.0


ADO. NET 2. 0 sports some exciting enhancements to the core classes found in ADO. NET 1. x and introduces a variety of new classes, all of which promise to improve performance, flexibility, and efficiency.

John Papa

MSDN Magazine November 2005

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 ?         

Linq query to DataTable


Is there option to convert from Linq.IQueryable to DataTable with some sort of CopyToDataTable() function. I am trying this.
     var row = from p in dc.ProductModels
                  select p;
    DataTable dt = row.CopyToDataTable();

Is there option to convert from Linq.IQueryable to DataTable with some sort of CopyToDataTable() function. I am trying this.

     var row = from p in dc.ProductModels


DataTable --> Oracle DB



Can someone offer advice on the below? 

I am connecting to an AR Server and pulling out data into a DataSet.  There will be 15 different DataTables within the set.  I would like to find a way to either insert the entire DataSet or each DataTable into an Oracle table.  The Oracle table has the same format as the DataTables I'm creating.

 private void button1_Click(object sender, EventArgs e)
                //Get Credentials
                ID = userNameTextBox.Text;
                PW = passWordTextBox.Text;

                connString = gstrConnectBaseLineStart + "UID=" + ID + ";PWD=" + PW + gstrConnectBaseLineEnd; //Connection string
                conn = new OdbcConnection(connString); //Create Connection
                conn.Open(); //Open Connection
                Console.Write("Connection Successful" + "\n");

                dataAdapter = new OdbcDataAdapter(SQL, conn);
                dataAdapter.Fill(IncidentsDataSet, "dataTableTest");

                DataTable dataTable = new DataTable();
                dataTable = IncidentsDataSet.Tables["dataTableTest"];

                dataGridView1.DataSource = dataTable;

                //Would like to create som

datatable select from ddl


I have a datatable with 3 columns: id, AdGrp, Desc.  I bind it to a drop downlist that has id as the selected value and AdGrp as the selected text. I also have a label that i would like to display the Desc column value when ever the ddl selected index changes.  I was thinking of using  a select on the datatable with the selected value but not sure how i to do that.  Here is the code i have so far:

 string filter = "Id={0}";

How to handle null while converting from my datatable to List<> using LINQ


I am converting my datatable to LISt using LINQ
how do I handle nulls coming from database

List<Port> portDetails = new List<Port>();
DataTable dt = ds.Tables[0];               
portDetails = (from q in dt.AsEnumerable()
select new Port
PortCode = q.Field<string>("Code"),
ExtCode = q.Field<string>("Nb"),
Name = q.Field<string>("Name"))

In the above query if Code is null I do not want property
portcode to be set to the value it should only set if it is
not null or not blank 
PortCode = q.Field<string>("Code"),

What should be syntax
I was trying somethign like this which doesnt work
Portcode = q.Field<bool>("Code") == null ? null : q.Field<bool>("Code")


From 3.5 to 2.0: No default member found for 'DataTable'



I'm trying to change the framework of an application I made a while from 3.5 back down to 2.0 as it's not compatible with the new server we put in (we're don't have permission to install 3.5 framework).

So, I went into the project properties and under the Compile tab, changed the project to 2.0. When I tried to publish the project I got a lot of errors and warnings and the publish failed.

In the 3.5 code, I had SQLSelect statement in a Dim which was labeled 'As DataTable'. When switching to 2.0, an error appears on the Dim saying: "Class 'System.Data.DataTable' cannot be indexed because it has no default property". So I simply took DataTable out of the code. Now, when I try to run the project, I get "No default member found for 'DataTable'.

Here's the code:

Function DisplayName(ByVal LoginName)

     Dim tempname(2) As String
     Dim signon As String

     tempname = Split(CheckUser(LoginName), "\")
     singon = tempname(1)

     Dim rst 'As DataTable
     rst = ExecSQLSelect("SELECT given_name, surname FROM ... etc")

     If rst.Rows.Count = 0 Then
          DisplayName = "Unknown"

          'This is where the error is:
          DisplayName = rst(0)("giv

using CompositeCollection in ListBox for merging two Typed DataTable

Hi i have a Typed DataSet contining two DataTable : Table1 , Table2 i want to merge the two Tables in a ListBox by using "CompositeCollection " , but this doesn't work <ListBox.ItemsSource> <CompositeCollection> <CollectionContainer Collection="{Binding Path = Table1}"/> <CollectionContainer Collection="{Binding Path =Table2}"/> </CompositeCollection> </ListBox.ItemsSource> i put also : public partial class Window1 : Window { public Window1() { InitializeComponent(); this.FillDataset(); this.DataContext = ds; //this.Resources.Add("mytable1", DataSet1.Table1); }   i want to confess i don't have a clear idea about referencing an object as a Typed DataTable. also if a want to Template my ListBox lique this :    <ListBox.ItemTemplate> <DataTemplate DataType="{x:Type myprog:DataSet1+Table1 }"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Path=ProductName}" Background="AliceBlue"/> </StackPanel> </DataTemplate> <DataTemplate DataType="{x:Type myprog:DataSet1+Table2 }"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Path=ProductName}&quo
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