Similar Threads:
1.problem with data adapter and data set while inserting and retrieving data
i am using a data adapter and a dataset for filling and retrieving data
into .mdb database.
following is the code.....
for the form load event
Dim dc(0) As DataColumn
Try
If OleDbConnection1.State = ConnectionState.Closed Then
OleDbConnection1.Open()
Else
MsgBox("connection can not be established")
End If
DA.Fill(DataSet11, "Table1")
cmd = New OleDbCommandBuilder(DA)
dc(0) = DataSet11.Tables("Table1").Columns("EmpID")
DataSet11.Tables("Table1").PrimaryKey = dc
Catch ex As Exception
MsgBox(ex.Message)
End Try
Delete.Enabled = False
End Sub
for inserting values into the DB
Private Sub Insert_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Insert.Click
Dim dr As DataRow
dr = DataSet11.Tables("Table1").NewRow
dr.Item(0) = Val(TB1.Text)
dr.Item(1) = TB2.Text
dr.Item(2) = TB3.Text
dr.Item(3) = Val(TB4.Text)
dr.Item(4) = TB5.Text
DataSet11.Tables("Table1").Rows.Add(dr)
DA.Update(DataSet11, "Table1")
MsgBox("data is saved")
rno = 0
call filldata()
filldata function consists of the following
With DataSet11.Tables("Table1").Rows(rno)
TB1.Text = Trim(.Item(0))
TB2.Text = Trim(.Item(1))
TB3.Text = Trim(.Item(2))
TB5.Text = Trim(.Item(4))
End With
the error it gives is " there is no row at
0........system.nullreference...........i checked the connection and
its working fine and also the database is getting accessed........the
error is occuring at the line " With
DataSet11.Tables("Table1").Rows(rno) "
2.Passing parameter for Stored Procedure to Data Adapter/Data Set
Hey all,
I'm trying to pass a parameter into my Stored procedure to be accessed by
my data adapter into a dataset
db2.AddParameter("@intClientID",
cmbClientList.SelectedValue.ToString());
DataSet rsDataset = db2.Fill("spListMappingDetails",
CommandType.StoredProcedure);
However, when i try to run it, it gives me an error
{"Procedure 'spListMappingDetails' expects parameter '@intClientId', which
was not supplied."}
Any help is appreciated.
I used a executescalar and executequery function and it has no problem.
thanks in advance
3.Provider independent data access: creating a data adapter from a connection
I have written a provider independent ado.net utility class for
executing queries. One of the routines looked like this in .net 1.1:
static public DataSet ExecuteQuery(IDbConnection connection, String sql)
{
connection.Open();
DataSet result = new DataSet();
IDbDataAdapter adapter = /* magic to create an adapter from a
connection*/
// The sybase adapter's implement IDisposable, so wrap with a using.
using(adapter as IDisposable)
{
adapter.SelectCommand.CommandText = sql;
adapter.SelectCommand.Connection = conn;
adapter.Fill(result);
}
return result;
}
The magic code to create the adapter was ugly: it essentially performed
a dictionary lookup on the type of connection, and created the resulting
adapter type. If IDbConnection had a method called CreateAdapter,
analagous to CreateCommand, this would have been cleaner.
With the introduction of ADO.NET 2.0 and the DbProviderFactory class, I
was hoping that some of the ugliness would go away. Unfortunately, I am
running into some problems. Namely
1- DbConnection still does not have a CreateAdapter method
2- DbConnection does not offer a way to get back to the
DbProviderFactory that created it.
So I still cannot create the correct adapter given only a generic
DbConnection. I am looking for suggestions on how to code my routine. So
far, I have thought of these
1- Make the user pass in the DbProviderFactory that goes with the
connection. CONS: forces users to use DBProviderFactory. We have a lot
of code that doesn't.
2- Stick with the dictionary lookup (Dictionary<ConnType, AdapterType>.
CONS: DLL dependencies explode.
3- Use a different dictionary lookup (Dictionary<ConnType,
DBProviderFactory>. CONS : A little messy, but better than 2.
4- Don't use provider specific adapters at all, just use a generic one.
Like this:
class GenericAdapter : System.Data.Common.DbDataAdapter
{
}
static public DataSet ExecuteQuery(DbConnection connection, String sql)
{
connection.Open();
DataSet result = new DataSet();
GenericAdapter adapter = new GenericAdapter();
adapter.SelectCommand = conn.CreateCommand();
adapter.SelectCommand.CommandText = sql;
adapter.Fill(result);
return result;
}
I have tested this with two databases, Sybase ASE and ASA, and it seems
to work. Are there any serious downfalls to not using the vendor
specific adapter type? Is this code safe?
H^2
4.Passing parameter for Stored Procedure to Data Adapter/Data Se
5.Manipulating data between data adapters
Hi
I have two data adapters bound to two separate tables. How can I;
1. Loop through all records one by one in one of them while reading column
values, and
2. Insert a record from data adapter A into data adapter B
via code?
Thanks
Regards
6. How to change data in grid after you change the SQL select for the data adapter
7. 3rd Tier data not displaying in Data Adapter Preview
8. How to change data in grid after you change the SQL select for the data adapter