locked
Why is my datatable empty, when my datagridview has data? RRS feed

  • Question

  • Hi,

    I try to update an ms access with data from a datagridview.

    i use the fill-function to put values into the datagridview: 
     
    this.dekl_Kjemiske_KriterierTableAdapter.Fill(this.specDBDataSet.Dekl_Kjemiske_Kriterier); 

    which work, but when I try to insert/update the values, it doesnt contain any values... 
    any suggestions to what I am doing wrong?

    1 OleDbConnection MSAccessConn = new OleDbConnection();  
    2             MSAccessConn.ConnectionString = (string)Settings.Default["SpecDBConnectionString"];  
    3             OleDbDataAdapter daMSAccess = new OleDbDataAdapter();  
    4  
    5             OleDbCommand updCommand = new OleDbCommand();  
    6             OleDbCommand insCommand = new OleDbCommand();  
    7  
    8                         // Query for Updating values in Chemical Criteria  
    9                     updCommand.CommandText = @"UPDATE Dekl_Kjemiske_Kriterier SET Minimum = :min, Maximum = :max, Deklarert = :setValue, Type = :Type WHERE    
    10                     AltProdNr = :AltProdNr AND DefinisjonID = :DefinisjonID";  
    11                     updCommand.CommandType = CommandType.Text;  
    12                     updCommand.Connection = MSAccessConn;  
    13                     updCommand.Parameters.Add(new OleDbParameter("min", OleDbType.Double, 0, "Minimum"));  
    14                     updCommand.Parameters.Add(new OleDbParameter("max", OleDbType.Double, 0, "Maximum"));  
    15                     updCommand.Parameters.Add(new OleDbParameter("setValue", OleDbType.Double, 0, "Deklarert"));  
    16                     updCommand.Parameters.Add(new OleDbParameter("Type", OleDbType.VarChar, 0, "Type"));  
    17                     updCommand.Parameters.Add(new OleDbParameter("AltProdNr", OleDbType.Integer, 0, "AltProdNr"));  
    18                     updCommand.Parameters.Add(new OleDbParameter("DefinisjonID", OleDbType.Integer, 0, "DefinisjonID"));  
    19                     daMSAccess.UpdateCommand = updCommand;  
    20  
    21                     // Query for Inserting values in Chemical Criteria  
    22                     insCommand.CommandText = @"INSERT INTO Dekl_Kjemiske_Kriterier (AltProdNr, DefinisjonID, Dato, Deklarert, Minimum, Maximum, Type)
    23                     VALUES (:AltProdNr, :DefinisjonID, Date(), :Deklarert, :Minimum, :Maximum, :Type)";  
    24                     insCommand.CommandType = CommandType.Text;  
    25                     insCommand.Connection = MSAccessConn;  
    26                     insCommand.Parameters.Clear();  
    27                     insCommand.Parameters.Add(new OleDbParameter("AltProdNr", OleDbType.Integer, 0, "AltProdNr"));  
    28                     insCommand.Parameters.Add(new OleDbParameter("DefinisjonID", OleDbType.Double, 0, "DefinisjonID"));  
    29                     insCommand.Parameters.Add(new OleDbParameter("Deklarert", OleDbType.Double, 0, "Deklarert"));  
    30                     insCommand.Parameters.Add(new OleDbParameter("Minimum", OleDbType.Double, 0, "Minimum"));  
    31                     insCommand.Parameters.Add(new OleDbParameter("Maximum", OleDbType.Double, 0, "Maximum"));  
    32                     insCommand.Parameters.Add(new OleDbParameter("Type", OleDbType.VarChar, 0, "Type"));  
    33                     daMSAccess.InsertCommand = insCommand;  
    34             // executing update/insert  
    35             MSAccessConn.Open();  
    36             daMSAccess.Update(this.specDBDataSet.Dekl_Kjemiske_Kriterier);  
    37             MSAccessConn.Close();  
    38             daMSAccess.Dispose();  
    39             MSAccessConn.Dispose(); 



    • Moved by jack 321 Thursday, June 5, 2008 8:44 AM off topic for C# general
    Tuesday, June 3, 2008 7:37 AM

Answers

All replies