Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / May 2005

Tip: Looking for answers? Try searching our database.

another obj ref error/ need help here

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
- 31 May 2005 18:29 GMT
im getting the dreaded:  
Object reference not set to an instance of an object.
on the code below. pretty new to C# but i know im missing something basic here.   

any help is appreciated
thanks
rik

public void GetEEs()
        {
           
SqlConnection myConnection = new SqlConnection("Data Source=(Local);Initial Catalog=A39;Integrated Security=SSPI");
SqlDataAdapter da = new SqlDataAdapter("GetAuditTimeCard",myConnection);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;
            da.SelectCommand.Parameters.Add("@PERIOD",SqlDbType.DateTime,8);
            da.SelectCommand.Parameters["@PERIOD"].Value = txtPpe.Text;
            DataSet ds = new DataSet();
            myConnection.Open();
            da.Fill(ds);
            Dg1.DataSource = ds.Tables["TimeCard"].DefaultView;
            Dg1.DataBind();
            da.Dispose();
            myConnection.Close();
}
larzeb - 31 May 2005 19:55 GMT
rik,

Did you create a new SqlCommand for your data adapter's SelectCommand?

 // Create the SelectCommand.

 cmd = new SqlCommand("SELECT * FROM Customers " +
                      "WHERE Country = @Country AND City = @City", conn);

 cmd.Parameters.Add("@Country", SqlDbType.NVarChar, 15);
 cmd.Parameters.Add("@City", SqlDbType.NVarChar, 15);

 da.SelectCommand = cmd;

Lars

>im getting the dreaded:  
>Object reference not set to an instance of an object.
[quoted text clipped - 24 lines]
>Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
>Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
rbutch@coair.com - 31 May 2005 20:35 GMT
yes i did.
and the command type was a stored procedure.

da.SelectCommand.CommandType = CommandType.StoredProcedure;

thanks
rik
larzeb - 31 May 2005 21:35 GMT
rik,

Where are you assigning the newly created SqlCommand to the new SqlDataAdapter? Something like:

da.SelectCommand = cmd;

>yes i did.
>and the command type was a stored procedure.
[quoted text clipped - 7 lines]
>Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
>Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
rbutch@coair.com - 31 May 2005 21:59 GMT
i thought what i sent you was that.
i basically ripped this right off of the microsoft website:

http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3BQ320916
rbutch@coair.com - 01 Jun 2005 00:29 GMT
i figured this one out. there are so many ways of doing things in .net both right and wrong. but, this one works just fine.
many many thanks for your help
rik

SqlConnection myConnection = new SqlConnection("Data Source=(Local);Initial Catalog=A39;Integrated Security=SSPI");

SqlCommand command = new SqlCommand("GetAuditTimeCard",myConnection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@PERIOD", SqlDbType.DateTime).Value = txtPpe.Text;
        SqlDataAdapter da = new SqlDataAdapter(command);
        DataSet ds = new DataSet();
               myConnection.Open();
        da.Fill(ds,"TimeCard");
        Dg1.DataSource = ds.Tables["TimeCard"].DefaultView;
        Dg1.DataBind();
               myConnection.Close();
               da.Dispose();

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.