DataTable Select Method problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?d2VzdGNvYXN0Y29kZQ==?=

    DataTable Select Method problems

    void CreateBatches(s tring currDir, DataTable hvTable) {
    string id;
    DirectoryInfo di = new DirectoryInfo(c urrDir);
    StreamWriter writer = new StreamWriter(cu rrDir + "\\Index.da t", false);
    DataRow[] rows;
    string tmpS;
    int i = 0;

    foreach (FileInfo fi in di.GetFiles("*. tmp"))
    {
    id = fi.Name.Remove( fi.Name.IndexOf ('.'));
    rows = hvTable.Select( "filename=" + id);


    I am using C# to make sure that a seelcted file exists in a datable before i
    write its data into a file, but in the code above it crashes at the last
    line. The error i get is "Could not find column [value of id]." If I put the
    same string, by hardcoding id, it works. What am I doing wrong?
  • Norman Yuan

    #2
    Re: DataTable Select Method problems

    Since id is a string value, you need

    rows = hvTable.Select( "filename=' " + id + ''");


    "westcoastc ode" <westcoastcode@ discussions.mic rosoft.comwrote in message
    news:EEE20712-3DF4-4D55-9810-21ECB2E14428@mi crosoft.com...
    void CreateBatches(s tring currDir, DataTable hvTable) {
    string id;
    DirectoryInfo di = new DirectoryInfo(c urrDir);
    StreamWriter writer = new StreamWriter(cu rrDir + "\\Index.da t",
    false);
    DataRow[] rows;
    string tmpS;
    int i = 0;
    >
    foreach (FileInfo fi in di.GetFiles("*. tmp"))
    {
    id = fi.Name.Remove( fi.Name.IndexOf ('.'));
    rows = hvTable.Select( "filename=" + id);
    >
    >
    I am using C# to make sure that a seelcted file exists in a datable before
    i
    write its data into a file, but in the code above it crashes at the last
    line. The error i get is "Could not find column [value of id]." If I put
    the
    same string, by hardcoding id, it works. What am I doing wrong?

    Comment

    Working...