Click here to Skip to main content
15,888,351 members
Home / Discussions / C#
   

C#

 
AnswerRe: code smell ? C# public class with everything i it declared 'static Pin
OriginalGriff8-Feb-23 8:12
mveOriginalGriff8-Feb-23 8:12 
GeneralRe: code smell ? C# public class with everything i it declared 'static Pin
Gerry Schmitz8-Feb-23 9:04
mveGerry Schmitz8-Feb-23 9:04 
AnswerRe: code smell ? C# public class with everything in it declared 'static Pin
englebart6-Mar-23 17:22
professionalenglebart6-Mar-23 17:22 
QuestionRunning MSBuild Commands from My C# console application. Pin
Madhurima Dutta7-Feb-23 4:56
Madhurima Dutta7-Feb-23 4:56 
AnswerRe: Running MSBuild Commands from My C# console application. Pin
Dave Kreskowiak7-Feb-23 5:18
mveDave Kreskowiak7-Feb-23 5:18 
AnswerRe: Running MSBuild Commands from My C# console application. Pin
jschell7-Feb-23 9:10
jschell7-Feb-23 9:10 
GeneralRe: Running MSBuild Commands from My C# console application. Pin
Madhurima Dutta8-Feb-23 4:46
Madhurima Dutta8-Feb-23 4:46 
GeneralRe: Running MSBuild Commands from My C# console application. Pin
jschell8-Feb-23 5:07
jschell8-Feb-23 5:07 
QuestionSystem.InvalidCastException: 'Unable to cast object of type 'System.Collections.Generic.List`1[FirstMVCApplication.Models.Products]' to type 'FirstMVCApplication.Models.Products'.' Pin
Member 136517316-Feb-23 21:41
Member 136517316-Feb-23 21:41 
AnswerRe: System.InvalidCastException: 'Unable to cast object of type 'System.Collections.Generic.List`1[FirstMVCApplication.Models.Products]' to type 'FirstMVCApplication.Models.Products'.' Pin
Eddy Vluggen7-Feb-23 1:13
professionalEddy Vluggen7-Feb-23 1:13 
AnswerRe: System.InvalidCastException: 'Unable to cast object of type 'System.Collections.Generic.List`1[FirstMVCApplication.Models.Products]' to type 'FirstMVCApplication.Models.Products'.' Pin
Gerry Schmitz7-Feb-23 13:26
mveGerry Schmitz7-Feb-23 13:26 
Questionxtendd Pin
PV20235-Feb-23 20:43
PV20235-Feb-23 20:43 
AnswerRe: xtendd Pin
OriginalGriff5-Feb-23 20:44
mveOriginalGriff5-Feb-23 20:44 
GeneralRe: xtendd Pin
PV20235-Feb-23 20:48
PV20235-Feb-23 20:48 
GeneralRe: xtendd Pin
Eddy Vluggen7-Feb-23 1:16
professionalEddy Vluggen7-Feb-23 1:16 
GeneralRe: xtendd Pin
RedDk7-Feb-23 7:05
RedDk7-Feb-23 7:05 
QuestionHow do I take datatable values into postgresql Pin
Member 141039872-Feb-23 8:22
Member 141039872-Feb-23 8:22 
AnswerRe: How do I take datatable values into postgresql Pin
Gerry Schmitz2-Feb-23 9:08
mveGerry Schmitz2-Feb-23 9:08 
GeneralRe: How do I take datatable values into postgresql Pin
jschell3-Feb-23 5:23
jschell3-Feb-23 5:23 
GeneralRe: How do I take datatable values into postgresql Pin
Gerry Schmitz3-Feb-23 7:10
mveGerry Schmitz3-Feb-23 7:10 
AnswerRe: How do I take datatable values into postgresql Pin
Dave Kreskowiak2-Feb-23 9:11
mveDave Kreskowiak2-Feb-23 9:11 
AnswerRe: How do I take datatable values into postgresql Pin
Richard MacCutchan2-Feb-23 21:40
mveRichard MacCutchan2-Feb-23 21:40 
AnswerRe: How do I take datatable values into postgresql Pin
jschell3-Feb-23 5:30
jschell3-Feb-23 5:30 
GeneralRe: How do I take datatable values into postgresql Pin
Member 141039873-Feb-23 21:33
Member 141039873-Feb-23 21:33 
Thanks for the suggestions. Here is an update that would explain everything in more detail.
I have a datatable with values, the first column will always be a string and the rest (5 columns) will have numbers. I have used the code that I shared to make it work for a datagridview but now I want to make it work for a datatable. The way I though was best was to take each row into the postgresql server and store it until its needed later. It seems like a sqladapter seems to be a better way to handle this and therefore I had some help trying to figure this out with the following code:
C#
using (NpgsqlDataAdapter adapter = new NpgsqlDataAdapter("SELECT num1, num2, num3, num4, num5, num6 FROM " + Table + ";", Conn))
  {
    NpgsqlCommand insert = new NpgsqlCommand("INSERT INTO " + Table + " VALUES (@num1, @num2, @num3, @num4, @num5, @num6);", Conn);
    insert.Parameters.Add("@num1", NpgsqlDbType.Text, 200, "1");
    insert.Parameters.Add("@num2", NpgsqlDbType.Text, 50, "2");
    insert.Parameters.Add("@num3", NpgsqlDbType.Text, 50, "3");
    insert.Parameters.Add("@num4", NpgsqlDbType.Text, 50, "4");
    insert.Parameters.Add("@num5", NpgsqlDbType.Text, 50, "5");
    insert.Parameters.Add("@num6", NpgsqlDbType.Text, 50, "6");

    adapter.InsertCommand = insert;
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    DataTable table = new DataTable();

    // Generate the DataTable schema.
    adapter.FillSchema(table, SchemaType.Source);

    // Add the new rows to the DataTable, e.g.
    DataRow row = table.NewRow();
    
    //Where I´m unsure what to do. This is obivously not the way to write the code but would appreciate it if I get some help to write this the right way
    row["1"] = row.Table.Rows[0][0].ToString(); //Does not continue after this line
    row["2"] = row.Table.Rows[0][1].ToString();
    row["3"] = row.Table.Rows[0][2].ToString();
    row["4"] = row.Table.Rows[0][3].ToString();
    row["5"] = row.Table.Rows[0][4].ToString();
    row["6"] = row.Table.Rows[0][5].ToString();
    
    table.Rows.Add(row);

    // Save the changes.
    adapter.Update(table);
  }
}


The code seems to work until the actual strings/values need to be put inside the SQL server table(see inside of code to know where the code breaks out). If anyone knows how to make the code work or is willing to show whats missing I would gladly appreciate it.
GeneralRe: How do I take datatable values into postgresql Pin
Dave Kreskowiak4-Feb-23 5:40
mveDave Kreskowiak4-Feb-23 5:40 

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.