Problem with for each statement
-
i am using foreach statement to read all the strings in a string array but while reading all the time it is showing System.Data.DataRow in the string identifier here is code which is giving the above specified problem: string[] fileidentifiers = ReturnFileIdentifiers(); foreach (string identifier in fileidentifiers) if (identifier == fileidentifier)
-
i am using foreach statement to read all the strings in a string array but while reading all the time it is showing System.Data.DataRow in the string identifier here is code which is giving the above specified problem: string[] fileidentifiers = ReturnFileIdentifiers(); foreach (string identifier in fileidentifiers) if (identifier == fileidentifier)
-
-
i am using foreach statement to read all the strings in a string array but while reading all the time it is showing System.Data.DataRow in the string identifier here is code which is giving the above specified problem: string[] fileidentifiers = ReturnFileIdentifiers(); foreach (string identifier in fileidentifiers) if (identifier == fileidentifier)
Then you're returning a collection of DataRows and you need to pull out the values that you need.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
i am using foreach statement to read all the strings in a string array but while reading all the time it is showing System.Data.DataRow in the string identifier here is code which is giving the above specified problem: string[] fileidentifiers = ReturnFileIdentifiers(); foreach (string identifier in fileidentifiers) if (identifier == fileidentifier)
-
i am using foreach statement to read all the strings in a string array but while reading all the time it is showing System.Data.DataRow in the string identifier here is code which is giving the above specified problem: string[] fileidentifiers = ReturnFileIdentifiers(); foreach (string identifier in fileidentifiers) if (identifier == fileidentifier)
kalaveer wrote:
System.Data.DataRow in the string identifier
what is your return statement in the ReturnFileIdentifiers(); function or while addding to the array of string you are not properly adding them in ReturnFileIdentifiers(); function
Thanks and Regards Sandeep If you want something you never had, do something you have never done!
-
Hello, Try to use a for loop, with an indexer!
for(int x=0;x < fileidentifiers.Length; x++)
{
as string;
if(actIdentifier.Equals(fileidentifier)
{}
}
Hope it helps! All the best, Martin
Even this is not working by the way my ReturnFileIdentifiers code would be below string[] ReturnFileIdentifiers() { using (OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\Warehouses_older\\Sample1_cat61.mdb")) { OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT MD_Metadata.FileIdentifier FROM MD_Metadata", connection); DataTable FileIDs = new DataTable(); adapter.Fill(FileIDs); string[] fileids = new string[FileIDs.Rows.Count]; for (int i = 0; i < FileIDs.Rows.Count; i++) fileids[i] = FileIDs.Rows[0].ToString(); return fileids; } }
-
Even this is not working by the way my ReturnFileIdentifiers code would be below string[] ReturnFileIdentifiers() { using (OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\Warehouses_older\\Sample1_cat61.mdb")) { OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT MD_Metadata.FileIdentifier FROM MD_Metadata", connection); DataTable FileIDs = new DataTable(); adapter.Fill(FileIDs); string[] fileids = new string[FileIDs.Rows.Count]; for (int i = 0; i < FileIDs.Rows.Count; i++) fileids[i] = FileIDs.Rows[0].ToString(); return fileids; } }
kalaveer wrote:
fileids[i] = FileIDs.Rows[0].ToString();
The
ToString
method ofDataRow
is inherited from theObject
class, and returns the name of the data type. What is is that you are trying to read from the data table?--- single minded; short sighted; long gone;
-
Even this is not working by the way my ReturnFileIdentifiers code would be below string[] ReturnFileIdentifiers() { using (OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\Warehouses_older\\Sample1_cat61.mdb")) { OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT MD_Metadata.FileIdentifier FROM MD_Metadata", connection); DataTable FileIDs = new DataTable(); adapter.Fill(FileIDs); string[] fileids = new string[FileIDs.Rows.Count]; for (int i = 0; i < FileIDs.Rows.Count; i++) fileids[i] = FileIDs.Rows[0].ToString(); return fileids; } }
-
i tried with your code but its working. i am pasting the code here please update using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace testApp { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private string[] ReturnFileIdentifiers() { string[] sample = { "sujith", "syam", "tharun" }; return sample; } private void button1_Click(object sender, EventArgs e) { string fileidentifier = "sujith"; string[] fileidentifiers = ReturnFileIdentifiers(); foreach (string identifier in fileidentifiers) if (identifier == fileidentifier) { MessageBox.Show("hi" + fileidentifier); } } } }
My small attempt...
-
kalaveer wrote:
fileids[i] = FileIDs.Rows[0].ToString();
The
ToString
method ofDataRow
is inherited from theObject
class, and returns the name of the data type. What is is that you are trying to read from the data table?--- single minded; short sighted; long gone;
-
Then you're returning a collection of DataRows and you need to pull out the values that you need.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
But while debugging fileids contents are the string values of that perticual field contents which i queried using oledb command.
The debugger is showing you the contents of the rows.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
You have a collection of data rows. Do a foreach that recognises this fact. You can get items out of a data row by index or by name, using array notation.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )