Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Bind DataTable to GridView problem
 

Bind DataTable to GridView problem

Hello all

I am using microsoft enterprise libraries for the first time, I wrote code to create database object and command, then I execute the command using Executedataset(command Object), I have no problem till this, then I try to get a datatable for the first item, to asign it to the Gridview I have, I got a null referance exception ..

Here is my code:

FileConfigurationSource fileSource = new FileConfigurationSource(@"filesource.config"); DatabaseProviderFactory dbFactory = new DatabaseProviderFactory(fileSource);

Database dbLTC = dbFactory.Create("LTCConnectionString");

DbCommand dbCommand = dbLTC.GetSqlStringCommand("select rin from master where officeid = 107"); try {

DataSet dset = dbLTC.ExecuteDataSet(dbCommand);

GridView1.DataSource = dset.Tables[0];

GridView1.DataBind();

Thanks and best regards

Waleed Seada  Monday, May 22, 2006 8:43 AM

Hi Waleed,
Can you provide with the stack trace of the exception?

Regards,
CodeCanvas

CodeCanvas  Monday, May 22, 2006 10:08 AM

Thanks for reply ...

Here is what I belive is the stack trace of the exception:

at RadMaster.Page_Load(Object sender, EventArgs e) in c:\Waleed Seada\dotNet\WebDev\RADAPP\RadMaster.master.cs:line 40
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.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Hope that helps

Thanks and best regards

Waleed Seada  Monday, May 22, 2006 1:37 PM

Hi Waleed Seada,

The null value is because the ExecuteDataSet evaluated to an empty dataset. So there is no table in the 0 location. Check your query against the database. See if you get results. If not then this is your problem. If it does return records, let me know and i will try to help.

Regards,

guy kolbis  Wednesday, May 24, 2006 9:27 PM

You can use google to search for other answers

Custom Search

More Threads

• How to change xsd file during runtime in vb.net
• Related ComboBox with BindingSource filter
• Can a User Control be used as a DataGridView's EditControl and "drop down" or "pop out" like a combo box or Calendar control?
• Heirarchal Binding Source
• Add check box to Coloumn header
• Integrity Error while using Typed Dataset
• DataBinding.Format and Parse
• Row validating event not firing in datagridview2005
• Data Binding textbox & Refreshing Textbox on record movement
• DataGridView containing a ComboBox column