Click here to Skip to main content
15,916,180 members
Home / Discussions / C#
   

C#

 
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 
AnswerRe: How do I take datatable values into postgresql Pin
Richard Deeming5-Feb-23 22:52
mveRichard Deeming5-Feb-23 22:52 
Question18 Errors Needs to be Fixed Pin
Michael Afolayan30-Jan-23 21:46
Michael Afolayan30-Jan-23 21:46 
AnswerRe: 18 Errors Needs to be Fixed Pin
Richard Deeming30-Jan-23 21:49
mveRichard Deeming30-Jan-23 21:49 
GeneralRe: 18 Errors Needs to be Fixed Pin
Michael Afolayan30-Jan-23 22:58
Michael Afolayan30-Jan-23 22:58 
GeneralRe: 18 Errors Needs to be Fixed Pin
Richard Deeming30-Jan-23 23:09
mveRichard Deeming30-Jan-23 23:09 
GeneralRe: 18 Errors Needs to be Fixed Pin
Richard MacCutchan30-Jan-23 23:11
mveRichard MacCutchan30-Jan-23 23:11 
GeneralRe: 18 Errors Needs to be Fixed Pin
Michael Afolayan30-Jan-23 23:23
Michael Afolayan30-Jan-23 23:23 
GeneralRe: 18 Errors Needs to be Fixed Pin
Richard MacCutchan30-Jan-23 23:09
mveRichard MacCutchan30-Jan-23 23:09 
GeneralRe: 18 Errors Needs to be Fixed Pin
Calin Negru1-Feb-23 1:00
Calin Negru1-Feb-23 1:00 
AnswerRe: 18 Errors Needs to be Fixed Pin
OriginalGriff30-Jan-23 22:09
mveOriginalGriff30-Jan-23 22:09 
GeneralRe: 18 Errors Needs to be Fixed Pin
Michael Afolayan30-Jan-23 23:15
Michael Afolayan30-Jan-23 23:15 
GeneralRe: 18 Errors Needs to be Fixed Pin
OriginalGriff31-Jan-23 2:06
mveOriginalGriff31-Jan-23 2:06 
GeneralRe: 18 Errors Needs to be Fixed Pin
CHill601-Feb-23 3:58
mveCHill601-Feb-23 3:58 
QuestionWhat's up with displaying transparent pixel? Closed Pin
mo149229-Jan-23 0:13
mo149229-Jan-23 0:13 
AnswerRe: What's up with displaying transparent pixel? Closed Pin
lmoelleb30-Jan-23 1:52
lmoelleb30-Jan-23 1:52 
QuestionWhy is my AlphaPanel approach to disable the entire GUI so slow? Pin
arnold_w25-Jan-23 4:45
arnold_w25-Jan-23 4:45 

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.