Click here to Skip to main content
15,898,371 members
Home / Discussions / C#
   

C#

 
GeneralRe: Unable to connect Oracle database from C# Pin
Dave Kreskowiak25-Apr-15 3:42
mveDave Kreskowiak25-Apr-15 3:42 
GeneralRe: Unable to connect Oracle database from C# Pin
meeram3925-Apr-15 5:46
professionalmeeram3925-Apr-15 5:46 
QuestionHow to Open the Docx File in Silverlight Pin
Hrishikesh Shivacharan24-Apr-15 1:17
Hrishikesh Shivacharan24-Apr-15 1:17 
AnswerRe: How to Open the Docx File in Silverlight Pin
Dave Kreskowiak24-Apr-15 3:37
mveDave Kreskowiak24-Apr-15 3:37 
AnswerRe: How to Open the Docx File in Silverlight Pin
Brisingr Aerowing24-Apr-15 6:31
professionalBrisingr Aerowing24-Apr-15 6:31 
AnswerRe: How to Open the Docx File in Silverlight Pin
Mycroft Holmes24-Apr-15 13:35
professionalMycroft Holmes24-Apr-15 13:35 
GeneralRe: How to Open the Docx File in Silverlight Pin
Hrishikesh Shivacharan6-May-15 21:20
Hrishikesh Shivacharan6-May-15 21:20 
GeneralRe: How to Open the Docx File in Silverlight Pin
Mycroft Holmes6-May-15 22:10
professionalMycroft Holmes6-May-15 22:10 
QuestionAdmin questions about Microsoft exam 70-483 Pin
CRobert45623-Apr-15 4:57
CRobert45623-Apr-15 4:57 
AnswerRe: Admin questions about Microsoft exam 70-483 Pin
Dave Kreskowiak23-Apr-15 9:39
mveDave Kreskowiak23-Apr-15 9:39 
GeneralRe: Admin questions about Microsoft exam 70-483 Pin
Mycroft Holmes23-Apr-15 12:56
professionalMycroft Holmes23-Apr-15 12:56 
QuestionHow to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell23-Apr-15 4:33
Norris Chappell23-Apr-15 4:33 
AnswerRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Sascha Lefèvre23-Apr-15 4:49
professionalSascha Lefèvre23-Apr-15 4:49 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell23-Apr-15 5:44
Norris Chappell23-Apr-15 5:44 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Sascha Lefèvre23-Apr-15 5:56
professionalSascha Lefèvre23-Apr-15 5:56 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell23-Apr-15 6:20
Norris Chappell23-Apr-15 6:20 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Kevin Marois23-Apr-15 6:37
professionalKevin Marois23-Apr-15 6:37 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Sascha Lefèvre23-Apr-15 6:55
professionalSascha Lefèvre23-Apr-15 6:55 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell23-Apr-15 13:21
Norris Chappell23-Apr-15 13:21 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Sascha Lefèvre24-Apr-15 3:00
professionalSascha Lefèvre24-Apr-15 3:00 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell24-Apr-15 5:25
Norris Chappell24-Apr-15 5:25 
Sascha,

Would something like this code work ? I'm really very new to C#. I think option 2 would be more in line with what I could do.

Thanks,

Noris


DataTable dt = new DataTable();

string line = null;

int i = 0;

 

using (StreamReader sr = File.OpenText(@"c:\temp\table1.csv"))

{   

      while ((line = sr.ReadLine()) != null)

      {

            string[] data = line.Split(',');

            if (data.Length > 0)

            {

                  if (i == 0)

                  {

                  foreach (var item in data)

                  {

                        dt.Columns.Add(new DataColumn());

                  }

                  i++;

             }

             DataRow row = dt.NewRow();

             row.ItemArray = data;

             dt.Rows.Add(row);

             }

      }

}

using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConsoleApplication3.Properties.Settings.daasConnectionString"].ConnectionString))

{

      cn.Open();

      using (SqlBulkCopy copy = new SqlBulkCopy(cn))

      {

            copy.ColumnMappings.Add(0, 0);

            copy.ColumnMappings.Add(1, 1);

            copy.ColumnMappings.Add(2, 2);

            copy.ColumnMappings.Add(3, 3);

            copy.ColumnMappings.Add(4, 4);

            copy.DestinationTableName = "Censis";

            copy.WriteToServer(dt);

      }

}  


For option 2

this is what I came up with for the SqlDataAdapter part:


public static SqlDataAdapter CreateCustomerAdapter(
SqlConnection connection)
{
SqlDataAdapter adapter = new SqlDataAdapter();


// Create the InsertCommand.
command = new SqlCommand(
"INSERT INTO Tempname(ResourceName) " +
"VALUES (@ResourceName)", connection);

// Add the parameters for the InsertCommand.
command.Parameters.Add("@ResoureName", SqlDbType.NVarChar, 50, "ResourceName");

adapter.InsertCommand = command;



return adapter;
}

I not able to download/integrate the CSV-Reader on this server. I will need to pursuit another route.

modified 24-Apr-15 11:56am.

AnswerRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Sascha Lefèvre24-Apr-15 11:04
professionalSascha Lefèvre24-Apr-15 11:04 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell24-Apr-15 11:57
Norris Chappell24-Apr-15 11:57 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Sascha Lefèvre24-Apr-15 12:56
professionalSascha Lefèvre24-Apr-15 12:56 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell25-Apr-15 13:28
Norris Chappell25-Apr-15 13:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.