sql - There are not enough fields in the Structured type. Structured types must have at least one field C# -
i have problem in winforms, when pass data-table sql-server through store procedure, got error same title question. can me solve ?
method execdb in class dbhelper connect sql , pass data :
public static dataset execdb(string procname, params object[] obj) { sqlconnection sqlcon = new sqlconnection(constring); if (sqlcon.state == connectionstate.closed) sqlcon.open(); sqldataadapter da = new sqldataadapter(procname, sqlcon); da.selectcommand.commandtype = commandtype.storedprocedure; sqlcommandbuilder.deriveparameters(da.selectcommand); if (da.selectcommand.parameters.count - 1 != obj.length) throw new exception("error"); int index = 0; foreach (sqlparameter pr in da.selectcommand.parameters) { if (pr.direction == parameterdirection.input || pr.direction == parameterdirection.inputoutput) { pr.value = obj[index++]; //pr.sqldbtype = sqldbtype.structured; } } dataset ds = new dataset(); da.fill(ds); if (sqlcon.state == connectionstate.open) sqlcon.close(); return ds; } here's datatable pass:
datatable dt = new datatable(); dt.clear(); dt.columns.add("ngaygiam", typeof(datetime)); dt.columns.add("tile", typeof(int)); dt.columns.add("thang", typeof(string)); dt.columns.add("mamon", typeof(int)); datarow dr = dt.newrow(); dr["ngaygiam"] =convert.todatetime(i.subitems[0].text); dr["tile"] =convert.toint32(tbxtilegiam.text); dr["thang"] = twomonth.substring(twomonth.length - 2) + datetime.now.year; dr["mamon"] = convert.toint32(i.tag.tostring()); dt.rows.add(dr); and here's structure in sql:
create type banggiamgia table( ngaygiam date not null, tile int not null, thang varchar(6) not null, mamon int not null ) and proc in sql :
create proc sp_updategiamgia @temp banggiamgia readonly begin insert giamgia select b.ngaygiam, b.tile, b.thang, b.mamon @temp b select * giamgia month(ngaygiam) = month(getdate()) , year(ngaygiam) = year(getdate()) end i don't understand why it's. pls explain me.
thanks.
Comments
Post a Comment