Results 1 to 2 of 2

Thread: unable to find tablemapping or tablename????

  1. #1

    Thread Starter
    Addicted Member KingSatan's Avatar
    Join Date
    Feb 2006
    Posts
    185

    Angry unable to find tablemapping or tablename????

    ok.... im tired... the error is
    Code:
     "unable to find mapping name or table"tablname"
    the error line is

    Code:
    da.Update(ds, "tblTasks");

    using visualstudio.net2003 C#
    oledb database 2003


    heres the portion of my code i find relavent
    Code:
     private void Page_Load(object sender, System.EventArgs e)
    
          
    
                {
    
                      System.Data.OleDb.OleDbConnection odc = new OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;data source=Tasks.mdb");
                      
                      string sc;                  
    
                      sc = "SELECT tblTasks.strTask, tblTasks.memInstructions, tblTasks.dtmDuedate, tblTasks.strContact, tblTasks.strLocation FROM tblTasks";
    
                      System.Data.OleDb.OleDbDataAdapter da = new OleDbDataAdapter(sc, odc);
    
                      System.Data.DataSet ds = new DataSet();   
                      da.Fill(ds, "TblTasks");
                      DataGrid1.DataSource = ds.Tables["tblTasks"];
                      DataGrid1.DataBind();
                      Label1.Text="Unfinished Tasks";
    
                }
    
                private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    
                {
    
                      DataGrid1.EditItemIndex = e.Item.ItemIndex;
                      DataGrid1.DataBind();
    
                }
    
                private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    
                {
                      DataGrid1.EditItemIndex = -1;
                      DataGrid1.DataBind();
    
                }
                private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    
                {string sc;
    
                      sc = "SELECT tblTasks.strTask, tblTasks.memInstructions, tblTasks.dtmDuedate, tblTasks.strContact, tblTasks.strLocation FROM tblTasks";
                      DataSet ds = new DataSet();
                      System.Data.OleDb.OleDbConnection odc = new OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;data source=Tasks.mdb");                
    
                      System.Data.OleDb.OleDbDataAdapter da = new OleDbDataAdapter(sc, odc);
    
                      System.Data.OleDb.OleDbCommandBuilder cb = new OleDbCommandBuilder();
    
                      DataGrid1.DataSource = ds.Tables["tblTasks"];
    //    
    //                
                      TextBox tb, tb2, tb3, tb4, tb5;
                      string strTask, memInstructions, dtmDuedate, strContact, strLocation;
    
                      //string key = (DataGrid1.DataKeys[e.Item.ItemIndex]); string key is not used yet so it is commented out.
    
                      tb = ((TextBox)(e.Item.Cells[1].Controls[0]));
                      strTask = tb.Text;
                      tb2 = ((TextBox)(e.Item.Cells[2].Controls[0]));
                      memInstructions = tb2.Text;
                      tb3 = ((TextBox)(e.Item.Cells[3].Controls[0]));
                      dtmDuedate = tb3.Text;
                      tb4 = ((TextBox)(e.Item.Cells[4].Controls[0]));
                      strContact = tb4.Text;
                      tb5 = ((TextBox)(e.Item.Cells[5].Controls[0]));
                      strLocation = tb5.Text;
                      da.Update(ds, "tblTasks");
                      DataGrid1.EditItemIndex = -1;
                      DataGrid1.DataBind();
                }
          }

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: unable to find tablemapping or tablename????

    There is no DataTable with that name in your DataSet. In your Page_Load method you create a DataSet object and you populate a DataTable in it named "TblTasks". In your DataGrid1_UpdateCommand method you also create a DataSet object but you do not create or populate any DataTables in it. Those two DataSets are two distinct objects. The one that you pass to the Update method is the second one that has no tables in it. If you build a house and put furniture in it, then build another house, would you be surprised that the second house had no furniture? If you want to refer to the same DataSet object in both those methods then you need to declare a class-level variable. You would create a DataSet object and assign it to that variable in the Page_Load method, then you can access the same DataSet object via that variable in the DataGrid1_UpdateCommand method.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width