Problem with an Access query with parameters



Hy,
I have a problem showing results from a query with parameters (in Access) into a datagrid, if I use this code
I receive a System.NullReferenceException

DataTable myDt = new DataTable();
OleDbConnection myConnection = new OleDbConnection(ConfigurationSettings.AppSettings["strDB"]);
OleDbCommand myCommand = new OleDbCommand();
myCommand.Parameters.Add("Data", DayToShow); //DayToShow is a variable of type DateTime
myCommand.Connection = myConnection;
myCommand.CommandText = "myQuery";
myCommand.CommandType = CommandType.StoredProcedure;

OleDbDataAdapter myAdapt = new OleDbDataAdapter(myCommand);
myAdapt.Fill(myDt);
myDt.PrimaryKey = new DataColumn[] {myDt.Columns[0]};

if (myDt.Rows.Count>0)
{
dgDD.DataSource = myDt; //THIS ROW THROWS System.NullReferenceException
dgDD.DataBind();
}


But instead if I write the following code I see my data without errors....WHY?
Can someone help me? Thanks!

if (myDt.Rows.Count>0)
{
	for (int j=0; j<myDt.Rows.Count; j++)
	{
		for (int i=0; i<myDt.Rows[j].ItemArray.Length; i++)
		{
			Response.Write(myDt.Rows[j].ItemArray.GetValue(i).ToString()+"-");
		}
		Response.Write("<br>");
	}
}
.



Relevant Pages

  • Re: #Name error in Query
    ... Address (the table for mail/home address, a datagrid; ... a tab control with "contact" and others) ... So I'm using the following query to place the primary phone number from ...
    (microsoft.public.access.queries)
  • Re: other table that stores data differently than ADO.Net datatable?
    ... Since winforms doesn't have a datagrid that has "paging" to my knowledge. ... this query would return at least 500K addresses for the ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: binding datagrid to property hierarchy e.g. "Pet.Name"
    ... the binding collection instance, it will not find deep in and bind the ... For your Person class, implement ICustomTypeDescriptor interface, this ... Althrough this article is with PropertyGrid, DataGrid control will also ... query ICustomTypeDescriptor interface for class instance. ...
    (microsoft.public.dotnet.framework.windowsforms.databinding)
  • Re: Performance issue
    ... I have two queries to make and two data to display in a datagrid. ... first query and first data to display: ... a)query: the user enters some characters, the query selects the rows from ...
    (microsoft.public.sqlserver.ce)
  • Re: More columns than I asked for in columns collection
    ... query that determines which colums will appear in the DataGrid. ... Can you or anyone tell me how to limit the DataGrid to only those ... >> the columns collection editor. ...
    (microsoft.public.dotnet.framework.adonet)