473,379 Members | 1,243 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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>");
}
}
Nov 19 '05 #1
0 873

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Christopher Brandsdal | last post by:
Hi! I have a problem running my code on 2000 server and iis5.0. The code runs perfectly on my localhost (xp iis5.1) but when i run it on 2000 server iis5.0 I get this error: ...
1
by: Joris Kempen | last post by:
Hi people, I know that the question has come around sometimes: How to open an Access Report using ASP and export it to for example RTF. I'm trying to implement the first method of David...
13
by: Lee | last post by:
Hello All, First of all I would like to say thank you for all of the help I have received here. I have been teaching myself Access for about 4 years now and I've always been able to find a...
1
by: mtech1 | last post by:
Access 2002 I am trying to create a dynamic crosstab report that parameters come from 3 different forms. I get runtime error 3070 - The Microsoft Jet database engine does not recognize...
2
by: BillCo | last post by:
A2000, DAO 3.6 ref set, 2 Parameters in query from an unbound form. Dim db As DAO.Database Dim rst As DAO.Recordset Dim qryDef As DAO.QueryDef Dim prm As DAO.Parameter Set db = CurrentDb...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.