我正在尝试将使用C Sharp格式化的文本文件插入Microsoft SQL服务器。我有2个表Transaction和TMatch,我想在其中填充数据。每个4个属性。我为每个创建了2个类。我知道如何通过.Add()
和.SaveChanges()
手动将数据输入数据库。
这是我到目前为止所做的:
//Database insertions
TTransaction txn = new TTransaction();
**txn.Amount = 56; //I want a variable used below (AMOUNT) to go into amount.
txn.TRN = "sdfgsdfg";** //(TxnNo) to go into TRN
ScotiaNYAEntities context = new ScotiaNYAEntities();
context.TTransactions.Add(txn);
context.SaveChanges();
使用while循环遍历文本文件。
{
if (line.Contains("AMOUNT:")) //Look where to end for Transaction Text
{
// For Amount
IsAmount=true;
if(IsAmount)
{
Amount = line.Replace("AMOUNT:", String.Empty).Trim();
Console.WriteLine("AMOUNT: ********");
Console.WriteLine(Amount);
}
}..............................................
我不确定如何引用变量而不仅仅是值。
谢谢。
答案 0 :(得分:0)
// generate whole content with string addition and set by html()
var content = '<table id="t1"><tr><td>val1</td><td>val2</td><td>vall3</td>..</table>';
content += '<script>registerListeners("t1")</script>';
$('#mainContainer').html(content);
// will be called when table is set to DOM
function registerListeners(id) {
$('#t1').find('td').bind("click",function() {
cellClicked($(this[0]);});
}
function cellClicked(domCell) { // }
答案 1 :(得分:0)
这就是我所做的:
在for循环中逐行读取文件
String TxnLOC = null;
IsTransactionLocation= false;
if (line.Contains("TRANSACTION LOC:"))
{
IsTransactionLocation = true;
if (IsTransactionLocation)
{
TxnLOC = line.Replace("TRANSACTION LOC:", String.Empty).Trim();
Console.WriteLine("The Transaction Location: ********");
Console.WriteLine(TxnLOC);
//Database insertion fot TTransaction Table
TTransaction txn = new TTransaction();
txn.TRN = txnNo;
txn.Amount = Convert.ToDecimal(Amount);
txn.TransactionLocation = TxnLOC;
context.TTransaction.Add(txn); //Adding to the database
context.SaveChanges();
IsTxnSection = false;//For 1 to many relationship
}
}