所以,我知道你通过相关的列关联DataTable ...虽然我有一个小问题。无法将DataTable与另一个C#相关联
实施例:
父表 - 客户 - > {客户名称,customerCode(PK),telphoneCell,...等}
子表 - 订单 - > {customerCode,orderCode( PK)dateStart,dateEnd,...等}
现在......
孙表(S) - ManufacturingSheet - > {panelNumber,panelWidth,panelHeight,... etc}
还有一些文本框显示零件的数量,如螺栓&坚果,我从用户输入计算。
那么,如何将整个表单保存为单个客户订单呢?客户名称,代码和日期详细信息等也出现在此表单上。
即使我可以链接一个texbox到订单表,我将如何链接到表单的其余部分?
这里是代码显示所有网格&文本框,我想被存储在数据库:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PalisadeWorld
{
public partial class ManufacturingSheet : Form
{
public ManufacturingSheet()
{
InitializeComponent();
}
//all the calculated sizes, and parts
public string[] dis_Width { get; set; }
public string[] dis_Height { get; set; }
public string[] dis_Comments { get; set; }
public int[] dis_PaleQty { get; set; }
public int[] dis_Blocks { get; set; }
public int dis_num { get; set; }
//Method to Convert a string array to int array
private int[] ConvertArray(string[] s, int rows)
{
int[] intArray = new int[rows];
for (int x = 0; x < rows; x++)
{
intArray[x] = Convert.ToInt32(s[x]);
}
return intArray;
}
//Methods returning other parts calculated with sizes above
private int GetTotalBearers(string[] bearers, int rows)
{
int i;
int totalBearers = 0;
int[] temp = ConvertArray(bearers, rows);
for (i = 0; i < rows; i++)
{
if (temp[i] >= 2200)
{
totalBearers += 6;
}
else totalBearers += 4;
}
return totalBearers;
}
private int GetTotalPales(int[] pales, int rows)
{
int i;
int totalPales = 0;
for (i = 0; i < rows; i++)
{
totalPales += pales[i];
}
return totalPales;
}
private int GetTotalBoltsNutsBrackest(int[] pales, int rows)
{
int totalBolts = GetTotalPales(pales, rows) + (rows * 4);
return totalBolts;
}
private void ManufacturingSheet_Load(object sender, EventArgs e)
{
//displaying number of respective parts
numBearers.Text = string.Format("{0}", GetTotalBearers(dis_Height, dis_num));
numPales.Text = string.Format("{0}", GetTotalPales(dis_PaleQty, dis_num));
numBrackets.Text = numBearers.Text;
numBoltsNutsWashers.Text = string.Format("{0}", GetTotalBoltsNutsBrackest(dis_PaleQty, dis_num));
int i;
int no = 0;
//displaying sizes etc in DataGrid
for(i = 0; i < dis_num; i++)
{
// Create a new row.
PalisadeWorldDatabaseDataSet.ManufacturingSheetRow newOutputRow;
newOutputRow = palisadeWorldDatabaseDataSet1.ManufacturingSheet.NewManufacturingSheetRow();
newOutputRow.no = ++no ;
newOutputRow.cutSize = string.Format("{0}", dis_Width[i]);
newOutputRow.block = string.Format("{0}", dis_Blocks[i]);
newOutputRow.height = string.Format("{0}", dis_Height[i]);
newOutputRow.palesQty = string.Format("{0}", dis_PaleQty[i]);
newOutputRow.comments = string.Format("{0}", dis_Comments[i]);
// Add the row to the Region table
this.palisadeWorldDatabaseDataSet1.ManufacturingSheet.Rows.Add(newOutputRow);
// Save the new row to the database
this.manufacturingSheetTableAdapter.Update(this.palisadeWorldDatabaseDataSet1.ManufacturingSheet);
this.manufacturingSheetTableAdapter.Fill(this.palisadeWorldDatabaseDataSet1.ManufacturingSheet);
}
}
}
}
也许** ManufacturingSheet **更多是报告而不是数据集,但仍需要根据客户详细信息保存 – 2013-03-06 12:19:41