Click here to Skip to main content
15,914,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using oledbdataadapter..how to store multiple table in adapter...help me?
Posted
Comments
Philip Stuyck 31-Oct-12 3:39am    
You need an adapter per table. What you can do however is make it use multiple queries, but the logical layout of the result set must be the same. I am talking about strongtyped adapters here that you can configure using the GUI of VS in the dataset designer. For a normal adapter you can attach only 4 commands to it. One for retrieval, one for insert, one for delete and one for update.

1 solution

You can try this as it written in following method...

using System.Configuration;
using System.Data.OleDb;

public DataSet getYourData(int paramid)
{
DataSet _ds = new DataSet();
OleDbConnection _conn = null;
OleDbCommand _cmd = null;
OleDbDataAdapter _da = null;

try
{
string constr=ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString;
_conn = new OleDbConnection(constr);
_cmd = new OleDbCommand("sp_get_YourData/Your query text", _conn);
_cmd.CommandTimeout = 0;
_cmd.CommandType = CommandType.StoredProcedure;// or use CommandType.Text;

_da = new OleDbDataAdapter(_cmd);
//adding parameters to the commandojbect
_cmd.Parameters.Add(new SqlParameter("@paramid", SqlDbType.Int));
_cmd.Parameters["@paramid"].Value = paramid;

_da.TableMappings.Add("SourceTable", "DatasetTableName");
_da.TableMappings.Add("SourceTable1", "DatasetTableName1");
_da.TableMappings.Add("SourceTable2", "DatasetTableName2");
_da.TableMappings.Add("SourceTable3", "DatasetTableName3");
_da.TableMappings.Add("SourceTable4", "DatasetTableName4");

_ds.EnforceConstraints = false;

_da.Fill(_ds);
}
catch (OleDbException ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (_cmd != null)
{
_cmd.Dispose();
_cmd = null;
}
if (_da != null)
{
_da.Dispose();
_da = null;
}
}

return _ds;
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900