我使用网页上的按钮单击命令,使用以下代码将数据从一条记录复制并插入到另一条新记录:
Using cmd3 As New OleDbCommand("INSERT INTO tblPalletRecords (PackDay,
Grade, Grower, HarvestDate, Status, Quality) SELECT PackDay, Grade, Grower,
HarvestDate, Status, Quality FROM tblPalletRecords WHERE ID = @x", conn)
cmd3.Parameters.AddWithValue("@x", txbID.Text)
conn.Open()
cmd3.ExecuteScalar()
conn.Close()
End Using
一切正常,但现在我想在此记录中的其他两个字段中插入:PalletNumber和CaseCount。我要为PalletNumber字段和CaseCount字段插入的值在网页的文本框中找到。
最有效的方法是什么?
谢谢。
答案 0 :(得分:0)
您可以将它们作为using Excel = Microsoft.Office.Interop.Excel;
class Program
{
static void Main(string[] args)
{
ReadExcel.PrintAllCells(@"D:\some_place\some_excel.xlsx");
}
}
public class ReadExcel
{
public static void PrintAllCells(string location)
{
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(location);
foreach (var xlWorksheet in xlWorkbook.Worksheets)
{
Excel.Range xlRange = xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
// LOOPING THROUGH EXCEL CELLS STARTS WITH 1
// NOT WITH 0
for (int column = 1; column < colCount; column++)
{
for (int row = 1; row < rowCount; row++)
{
var CellData = xlRange.Cells[row, column].Value;
Console.WriteLine(CellData);
}
}
}
}
}
值的insert into ... select
中的参数。
SQL看起来像
select
Vb完整代码
INSERT INTO tblPalletRecords (PackDay, Grade, Grower, HarvestDate, Status, Quality,PalletNumber,CaseCount)
SELECT PackDay, Grade, Grower, HarvestDate, Status, Quality,@PalletNumber,@CaseCount
FROM tblPalletRecords
WHERE ID = @x