Click here to Skip to main content
15,905,785 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,

I have a table "Loads" with data as below


LoadNum LoadDate FileName TableName ClientID
60 2010-11-18 den_pat.dat GreatWestDenverLoad 123
61 2010-11-18 stl_pat.dat GreatWestStLouisLoad 123
62 2010-11-18 fac_pat.dat GreatWestFacetsLoad 123
63 2010-11-18 GWHLMTELIG.csv GreatWestILWULoad 123
64 2011-01-11 den_pat.dat GreatWestDenverLoad 123
65 2011-01-11 fac_pat.dat GreatWestFacetsLoad 123
66 2011-01-11 GWHLMTELIG.csv GreatWestILWULoad 123
67 2011-01-11 stl_pat.dat GreatWestStLouisLoad 123

i have to access all the load numbers with the same date and move them to another table.
For eg: All the load Num's 60,61,62,63 should be my input parameters to a procedure which moves the data to respective four tables(GreatwestDeneverWork,GreatWestStLouisWork,GreatWestFacetsWork,GreatWestILWUWork) i.e, 60 to GreatwestDeneverWork etc.,

i tried first taking all the distinct dates and save it in a list.
Then taking the dates one by one and then accessing it in where condition along with the four LoadNum as below


C#
List<String> readerDate = new List<String>();
            string Clientid = "123";
            SqlDataReader sqlrdr;
            SqlConnection sqlcon = new SqlConnection(strEligibility);
            SqlCommand strSqlcmd;
            strsql = "select distinct CONVERT(VARCHAR(10),LoadDate,120) from T_EligLoads where ClientID='" + Clientid.ToString() + "'";
            strSqlcmd = new SqlCommand(strsql, sqlcon);
            sqlcon.Open();
            sqlrdr = strSqlcmd.ExecuteReader();
            if (sqlrdr.HasRows)
            {
                while (sqlrdr.Read())
                {
                    readerDate.Add(sqlrdr.GetString(0));
                }
            }
            sqlrdr.Close();
            sqlcon.Close();
            foreach (string Txt in readerDate)
            {
                strsql = "select LoadNum,LoadDate,TableName from T_EligLoads where ClientID='" + Clientid.ToString() + "' and LoadDate='" + DateTime.Parse(Txt) + "' ";
                strSqlcmd = new SqlCommand(strsql, sqlcon);
                sqlcon.Open();
                sqlrdr = strSqlcmd.ExecuteReader();
                if (sqlrdr.HasRows)
                {
                    while (sqlrdr.Read())
                    {
                        
                    }
                }
            }


Now in the second loop where i am reading the datareader i have to access all the 4 load numbers and table names which would be the result of the query and send them to the stored procedure as parameters.

EXEC usp_LoadGreatWestEligibility @LoadNum1,@LoadnUm2,@LoadNUm3,@LoadNum4

eg: EXEC usp_LoadGreatWestEligibility 60,61,62,63

Could anyone please help me how should i read them and immediately execute so that i can read the data present for all the dates
Posted

1 solution

If you are able to do it another way, I would suggest the you look into changing your routine to use an
SQL
INSERT INTO
statement instead of selecting. Let the database to the work for you.
 
Share this answer
 
Comments
Espen Harlinn 22-Apr-12 8:35am    
5'ed!
[no name] 22-Apr-12 8:36am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900