Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need help with writing the code to accomplish a data transfer. Please include example/psuedo code in your answer.



Current Situation:
I have a web application I've built. I need to take an excel sheets data, which I've imported into SQL Server Mgmt Studio, and move it into another table. I have one webpage with 1 button responsible for the import event. In general this isn't that hard, it's just that I have 1 column in my imported table that is a name field and I need to convert it to a number (id) field.



What I have so far:
I've added comments to explain pieces of my code as well as to indicate where I need help writing the code.


C#
protected void uxImport_Click(object sender, EventArgs e)
       {
           var accountTrackerImportSVC = new AccountTrackerImportSVC();
           

           var dtInfo = GetContent(); // dtInfo is = to my Imported table
           // View connectiontype by description
           // Pass ConnectionType
           // if the connectiontype description exists grab the i.d
           // if not then create an id, either way insert an entry
           foreach (DataRow drItem in dtInfo.Rows)
           {
               var connectionType = drItem["ConnectionTypeDesc"].ToString();// connectionType is being looped by foreach statement, I'm using var to view each connectiontype in my import table.
               {
                   AccountTrackerImportDAL.ViewConnectonTypeByDesc(connectionType);
                   if (connectionType == null)
                   {
                       //var result = AccountTrackerImportDAL.ImportIntoAccountEntry();
                   }
                   else
                   {

                   }


                   // I need to split name.
                   // first name match if yes return Worker Num
               }
               //Check results
               if(result.Successful)
               {
                   uxInfoMsg.DisplayMessage(result.Message, InfoMessage. InfoMessageType.Success);
               }
               else
               {

               }
               // Hide progress indicator
               Master.HideProgressIndicator();
           }


Any ideas on how to approach this. I'm still new to C# so I'll do my best to answer your questions.





Posted

1 solution

SQL Pseudo code :


SQL
insert into SecondTableName
select Column1,Column2
from FirstTableName 
where YourConditionHere

C# Code:


C#
try
{
con.open();
cmd=new sqlcommand("insert into SecondTableName select Column1,Column2
from FirstTableName where YourConditionHere",conn);
cmd.executenonquery();
con.close();
}
catch(exception ex)
{
}
finally
{
 con.close();
}

Replace the Pseudo code Query with your real time query


It is better to do conversions and calculations with in the query
 
Share this answer
 
v2

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