Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write arraylist contents to database

Status
Not open for further replies.

itmastermd

IS-IT--Management
Jan 11, 2008
2
US
We are trying to debug a custom program and unfortunately the programmer is no longer with company. What the program is doing is parsing a text file and adding certain lines to an Arraylist. This ArrayList is one of 7 database fields which are populated from data parsed from these files. We show the ArrayList getting populated correctly but it is not writing to the database. Here is the line of code and variable declaration which I am referring. Any suggestions?

ArrayList Text = null;

DR["BookMarkText"] = string.Join("\r\n", (string[])Text.ToArray(typeof(string)));
 
not writing to the database

the code fragment you hilight assigns a value to a database field in memory.

could you post the bit that actually does the writing to the database?



mr s. <;)

 

Here you go. As I stated, all other info populates fine except for the data from the ArrayList.

DataRow DR = null;
try
{
Table = SqlQuery.QueryTable(DSN,
string.Format("SELECT * FROM [TextFeed] WHERE VisitID='{0}' AND DocType='{1}'", PI.VisitID,PI.DocType));
Table.TableName = Path.GetFileName(TextFile);
DR = Table.Rows.Count > 0 ? Table.Rows[0] : Table.NewRow();
DR["VisitID"] = PI.VisitID;
if (PI.Name != string.Empty)
DR["PatientName"] = PI.Name;
if (PI.MRN != string.Empty)
DR["MRN"] = PI.MRN;
if (PI.DocType != string.Empty)
DR["DocType"] = PI.DocType;
DR["BookMarkText"] = string.Join("\r\n", (string[]) Text.ToArray(typeof(string)));
DR["TextAddedToDoc"] = 0;
if (Table.Rows.Count == 0)
Table.Rows.Add(DR);
SqlQuery.UpdateTable(Table);
Console.Write("Success");
}
 
in your code, where does "Text" get its value? Are you sure it is being assigned one?

Code:
try
        {
            Table = SqlQuery.QueryTable(DSN,string.Format("SELECT * FROM [TextFeed] WHERE VisitID='{0}' AND DocType='{1}'", PI.VisitID, PI.DocType));
            Table.TableName = Path.GetFileName(TextFile);
            DR = Table.Rows.Count > 0 ? Table.Rows[0] : Table.NewRow();
            DR["VisitID"] = PI.VisitID;
            if (PI.Name != string.Empty)
                DR["PatientName"] = PI.Name;
            if (PI.MRN != string.Empty)
                DR["MRN"] = PI.MRN;
            if (PI.DocType != string.Empty)
                DR["DocType"] = PI.DocType;
            DR["BookMarkText"] = string.Join("\r\n", (string[])[b]Text[/b].ToArray(typeof(string)));
            DR["TextAddedToDoc"] = 0;
            if (Table.Rows.Count == 0)
                Table.Rows.Add(DR);
            SqlQuery.UpdateTable(Table);
            Console.Write("Success");
        }
        catch (exception ex)
        {
        }

Also, indentation and use of TGML makes your code easier to read. I would recommend doing so in the future to get the best responses to your questions.

Kevin Davie
Consultant
Sogeti USA
 
Actually, I should have paid more attention to your code. What are your trying to do here?

Code:
string.Join("\r\n", (string[])Text.ToArray(typeof(string)));

That is an invalid cast, which is probably what your issue is. What are you actually trying to get into the BookMarkText column?

-Kevin

Kevin Davie
Consultant
Sogeti USA
 
I think the line
Code:
DR["BookMarkText"] = string.Join("\r\n", (string[]) Text.ToArray(typeof(string)));
is Okay.
Questions to see in order:
1)
What is the field type in database for BookMarkText ?
If it is varchar or nvarchar then maybe the field is not updated because of truncation.
2) What is the code of SqlQuery.UpdateTable() ?

obislavu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top