Advertisement

05.08.2008 at 08:51AM PDT, ID: 23386526
[x]
Attachment Details

DataRow find problem C#

Asked by copyPasteGhost in C# Programming Language

I'm getting this error:  Input string was not in a correct format.

this is the code...

This is the line that failes:

DataRow drFiltered = ds.Tables[0].Rows.Find(tagname);

tagname is a string containing "FName"


Thanks,
Ghost
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
public static DataSet dbValueGet() {
            DataSet ds = new DataSet();
            string connection = ConfigurationManager.ConnectionStrings["LocalConnection"].ConnectionString;
            SqlConnection con = new SqlConnection(connection);
            string sql = "SELECT * FROM Tags; SELECT * FROM TagLanguage";
 
            //Query tables and add to Dataset.
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataAdapter daTagLanguage = new SqlDataAdapter(cmd);
            daTagLanguage.Fill(ds);  
            return ds;
        }
 
 
THIS IS THE METHOD THAT FAILES
public static string cacheValueGet(string tagname, out bool isDefined) {
            string rtnStr = "Undefined";
            isDefined = false;
 
            DataSet ds = null; 
            if (ds == null) {
                ds = db.dbValueGet();
                //table index 1 = [dbo.Tags]
                //table index 0 = [dbo.TagLanguage]
 
                //Set tags Primary Key
                DataTable dtTags = ds.Tables[0];
                DataColumn[] dcTagsPrimary = { dtTags.Columns["id"] };
                dtTags.PrimaryKey = dcTagsPrimary;
 
                //Set tags Primary Key
                DataTable dtTagLangs = ds.Tables[1];
                DataColumn[] dcTagsLangsPrimary = { dtTagLangs.Columns["TagID"], dtTagLangs.Columns["LangID"] };
                dtTagLangs.PrimaryKey = dcTagsLangsPrimary;
 
                //Set up the dataset Relationship
                DataColumn[] dcTagsForeign = new DataColumn[] { ds.Tables[0].Columns["id"] };
                DataColumn[] dcTagsLangsForeign = new DataColumn[] { ds.Tables[1].Columns["TagID"] };
 
                DataRelation TagsLangs_Tags = new DataRelation("TagLangRelationship", dcTagsForeign, dcTagsLangsForeign);
                ds.Relations.Add(TagsLangs_Tags);
 
                //Add the dataset into cache
 
            }
                      DataRow drFiltered = ds.Tables[0].Rows.Find(tagname);
       
 
                   if (drFiltered != null) {
                //then you know you have the records filtered.
            
                return drFiltered[0].ToString();
 
            }
            else {
                isDefined = false;
            }
 
            return rtnStr;
}
[+][-]05.08.2008 at 08:57AM PDT, ID: 21525858

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.08.2008 at 01:03PM PDT, ID: 21527989

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.10.2008 at 07:39PM PDT, ID: 21541297

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C# Programming Language
Sign Up Now!
Solution Provided By: rod4nillos
Participating Experts: 3
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906