DataTable Select Method problems


G

Guest

void CreateBatches(string currDir, DataTable hvTable) {
string id;
DirectoryInfo di = new DirectoryInfo(currDir);
StreamWriter writer = new StreamWriter(currDir + "\\Index.dat", 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?
 
Ad

Advertisements

N

Norman Yuan

Since id is a string value, you need

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top