Answered by:
error on _ds.Relations.Add

Question
-
User222331888 posted
Hi,
I don't know why I've an error on this :
_ds.Relations.Add("Polls_Answers", _ds.Tables["Polls"].Columns["PollID"], _ds.Tables["PollAnswers"].Columns["PollID"]);
My error is :{"Object reference not set to an instance of an object."}
conn.Open(); string strSql = "SELECT GroupID, GroupName FROM [Group]; " + "SELECT PollID, DisplayText, Type, GroupID, FolderID " + "FROM Polls, TypeAns where Polls.TypeAnsID = TypeAns.TypeAnsID; " + "SELECT PollID, PollAnswerID, DisplayText, SortOrder FROM" + " PollAnswers"; SqlDataAdapter da = new SqlDataAdapter(strSql, conn); da.TableMappings.Add("Group1", "Polls"); da.TableMappings.Add("Group2", "PollAnswers"); DataSet _ds = new DataSet("Polls"); da.Fill(_ds, "Polls"); _ds.Relations.Add("Polls_Answers", _ds.Tables["Polls"].Columns["PollID"], _ds.Tables["PollAnswers"].Columns["PollID"]); _ds.Relations[0].Nested = true; _ds.Relations.Add("Polls_Group", _ds.Tables["Polls"].Columns["GroupID"], _ds.Tables["[Group]"].Columns["GroupID"]); _ds.Relations[1].Nested = true; Repeater1.DataSource = _ds.Tables["Polls"]; Repeater1.DataBind(); conn.Close();
Thanks a lot for your help,
Thursday, May 27, 2010 4:12 AM
Answers
-
User222331888 posted
SqlDataAdapter da = new SqlDataAdapter(strSql, conn); da.TableMappings.Add("Table", "Group"); da.TableMappings.Add("Table1", "Polls"); da.TableMappings.Add("Table2", "PollAnswers");
Sorry my bad that was coming from my missing mapping.Now it works fine,
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, May 27, 2010 7:31 AM
All replies
-
User222331888 posted
Hi,
My error come from
DataColumn table1Column; table1Column = _ds.Tables["Polls"].Columns[0];
My error is still :System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_ygpup3yr"
StackTrace:
at Quest.Page_Load(Object sender, EventArgs e) in c:\...\Quest.aspx.cs:line 39
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
and my
_ds.Tables["Polls"].Columns[0] '_ds.Tables["Polls"]' is null System.Data.DataColumn
So obviously come from my request, where did I messed up? cuz if i apply request by request it works.
Thanks for your help,Thursday, May 27, 2010 6:29 AM -
User222331888 posted
Hi,
when i feel in my dataset, my tables are there cuz I can see three tables, but then when I check TableNamei've
"Table"
"Table1"
"Table2"
in ((System.Data.DataTable)((new System.Collections.ArrayList.ArrayListDebugView(((System.Data.DataTableCollection)(((System.Data.InternalDataCollectionBase)(_ds.Tables)).SyncRoot)).List)).Items[0])).TableName
But in ColumnName, i've the good name of column :
((System.Data.DataColumn)((new System.Collections.ArrayList.ArrayListDebugView(((System.Data.InternalDataCollectionBase)(((System.Data.DataTable)((new System.Collections.ArrayList.ArrayListDebugView(((System.Data.DataTableCollection)(((System.Data.InternalDataCollectionBase)(_ds.Tables)).SyncRoot)).List)).Items[0])).Columns)).List)).Items[1])).ColumnName
GroupId, GroupName....
Any idea?
Thursday, May 27, 2010 7:23 AM -
User222331888 posted
SqlDataAdapter da = new SqlDataAdapter(strSql, conn); da.TableMappings.Add("Table", "Group"); da.TableMappings.Add("Table1", "Polls"); da.TableMappings.Add("Table2", "PollAnswers");
Sorry my bad that was coming from my missing mapping.Now it works fine,
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, May 27, 2010 7:31 AM