![](/img/trans.png)
[英]Procedure or function 'sp_getchech' expects parameter '@ID', which was not supplied
[英]Procedure or function 'procname' expects parameter '@id', which was not supplied
我想將值插入存儲在數組list中的數據庫中。但是在插入時出現此錯誤,我嘗試了不同的方法,但是它不起作用,有人可以幫助我在此處輸入代碼嗎?
public void Test_Get_Table_From_Grasshopper_Home(int id, DateTime Date,string fromphone, string ext,string type,DateTime created)
{
cw("Retrieving grasshopper page...");
string filepath = string.Format(@"\home.htm", localprojectpath);
var calls = new List<Call>();
using (WebZinc webZinc = new WebZinc())
{
webZinc.OpenPage(filepath);
WhiteCliff.WebZinc.Objects.Table table_calls = webZinc.CurrentPage.GetHtmlElements("div", "grid_messages")[1].Tables[0];
if (table_calls.Rows.Count > 0)
{
foreach (TableRow tr in table_calls.Rows)
{
if (tr.Cells.Count > 0)
{
var singlecall = new Call
{
date = tr.Cells[0].Text, ext = tr.Cells[1].Text, fromphone = tr.Cells[2].Text,type = tr.Cells[3].Text
};
calls.Add(singlecall); calls.
}
}
}
SqlConnection connection = new SqlConnection(
@"Data Source=;Initial Catalog=;User ID=sa;Password=123");
connection.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = connection;
cmd.CommandText = "dbo.nameproc";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", id);
cmd.Parameters.AddWithValue("@fromphone", fromphone);
cmd.Parameters.AddWithValue("@date", Date);
cmd.Parameters.AddWithValue("@ext", ext);
cmd.Parameters.AddWithValue("@type", type);
cmd.Parameters.AddWithValue("@created", created);
cmd.ExecuteNonQuery();
Console.WriteLine("insert sucessfull done");
}
if (calls.Count > 0)
{
foreach (var call in calls)
{
cw(string.Format("{0} - {1} - {2}-{3}", call.date, call.ext, call.fromphone, call.type));
}
}
}
}
}
public class Call
{
public string id { get; set; }
public string date { get; set; }
public string fromphone { get; set; }
public string ext { get; set; }
public string type { get; set; }
public string created { get; set; }
}
SP:
ALTER procedure [dbo].[nameproc]
(@id int ,@date datetime,@fromphone varchar(50),@ext varchar(50),@type varchar(50),@created datetime)
AS
BEGIN
Insert into GrasshopperLog (id,date,fromphone,ext,type,created)
Values(@id,@date,@fromphone,@ext,@type,@created)
END
該錯誤不言自明。
您存儲的proc dbo.homeproc
希望您提供一個參數。
cmd.Parameters.AddWithValue("id", some_variable_holding_an_id);
編輯:
cmd.Parameters.AddWithValue("@id",SqlDbType.Int).Value=id;
應該:
cmd.Parameters.AddWithValue("@id",id);
請嘗試將參數按順序傳遞給存儲過程,可能會有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.