嘗試在C#中插入已發佈到數據庫頁面的數據。當我將它寫入文件時,我可以看到發佈的數據。但是,當我嘗試將它插入到表中時,它並未插入它。但是,如果不使用發佈的數據,我使用插入的硬編碼數據。我無法調試,因爲發佈的數據只有在我上傳到服務器時纔會發佈到頁面。但插入部分是工作文件,我嘗試使用測試數據。當我使用發佈的數據時,插入不工作C#
這是我的代碼:
if (Request.HttpMethod.ToString() == "POST")
{
StreamWriter sw = new StreamWriter(@"C:\IIS\wwwroot\MailGun\text.txt");
sw.Write("You sent a post!" + "recipient: " + Request["recipient"] + "event: " + Request["event"]);
//here it is writing posted data in file and I check it is there.
sw.Close();
recipient = Request["recipient"]; //this is where I have problem I think.
event1 = Request["event"];
InsertWebhook();
}
protected void InsertWebhook()
{
Webhookfields webhookfields = new Webhookfields();
webhookfields.event =event1;
webhookfields.recipient =recipient;
webhookfields = DataManager.InsertWebhook(webhookfields);
}
public string recipient { get; set; }
public string event1 { get; set; }
如果不是這樣的我用這個代碼,它被插入:
string recipient = "recipient test";
string event1 = "event test"
InsertWebhook();
我發現這個問題。在要插入的存儲過程中,我必須識別默認的空值。現在插入。
你用什麼類型的庫將數據保存到數據庫? – Luaan
保存數據正在工作,這是我很確定。 – Alma
僅供參考 - 不知道這是否會破壞你的代碼 - 你有一個額外的'+'操作符,在'+ Request [「recipient」] + +「event:」' –