Insert DataTable rows to DataBaseTables using DataAdapter: leave out one column in DataTable

StackOverflow https://stackoverflow.com/questions/17509210

  •  02-06-2022
  •  | 
  •  

سؤال

i have DataTable named dtPurchaseProduct that has columns

  • dtcolPurchaseProduct_No
  • dtcolnInvoiceNo
  • dtcolnProductNo
  • dtcolnProductName
  • dtcolnQuantity
  • dtcolnPrice

these are bound to datagridview except dtcolnProductNo because only product names are required to be seen

and i have DatabaseTable Named PurchaseProduct that has columns

  • PurchaseProduct_No
  • InvoiceNo
  • ProductNo
  • Quantity
  • Price

now after allowing user to add/update/delete the DataTable rows through textboxes i want to insert these rows to DataBaseTable with DataAdapter

Is it possible to do that? i don't have select command and even the columns are not exactly the same that is i don't have database column for dtlcolnProductName

هل كانت مفيدة؟

المحلول

string qry = "select * from PurchaseProduct where 0 = 1";
        sa = new SqlDataAdapter(qry, conn);
        dataSet = new DataSet();
        sa.Fill(dataSet);
        dataSet.Tables[0].Columns.Add("dtcolnPurchaseProductProductName",typeof(string));
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top