DataSource Controls :: Create A Class Like SqlHelper.cs?

Apr 9, 2010

string connectionString = (string)
ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand("INSERT_PERSON",connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@Name",SqlDbType.NVarChar,50));
command.Parameters["@Name"].Value = txtName.Text;
command.Parameters.Add(new SqlParameter("@Age",SqlDbType.NVarChar,10));
command.Parameters["@Age"].Value = txtAge.Text;
connection.Open();
command.ExecuteNonQuery();
connection.Close();

Above is my code.

I has more than 100 methods like this, so every time i'm opening the connection and close it, this will take too much of time, what i think is instead of this i would like to create the class for Connection open, that class will check whether the connection is closed or Broken then Open it(like SqlHelper.cs) so without big change on my methods, how to create that class and how to access that class from my methods.

View 5 Replies


Similar Messages:

DataSource Controls :: Aplication Real Slow, Using Sqlhelper

Dec 18, 2010

I hired some to write a ecommerce website for me.and the used SqlHelper.GetInstance().ExecuteDataSet stuff i'm not familiar with.
But is real slow .
Screenshot of trace,page takes like +20 sec to return like 20 records of 3 field each!The DB queries are good, use same SP on my own app and it takes les then 1 sec.Did they use the sqlhelper wrong? is sql helper that slow?

View 1 Replies

ADO.NET :: Difference Between Sqlhelper.ExecuteReader And Sqlhelper.ExecuteXmlReader?

Dec 24, 2010

what is the exact difference between Sqlhelper.ExecuteReader and Sqlhelper.ExecuteXmlReaderand which on is faster

View 3 Replies

C# - Substitute For Microsoft Data Access ApplicationBlocks Obsolete SqlHelper Class?

Dec 16, 2010

It looks that the old SqlHelper class from the Microsoft Enterprise Library has been mostly replaced by the Database class which is included in the new Enterprise Library version 5.

I have a very simple and trivial example:
using Microsoft.ApplicationBlocks.Data;
private void PopulateCheckBoxGroup()
{
const string strConnTxt = "Server=(local);Database=DataBindTests;Integrated Security=True;";
const string strlSql = "select Technology from PreferredTechnology where ParentId = 1";
CheckBoxList1.DataSource = SqlHelper.ExecuteReader(strConnTxt, CommandType.Text, strlSql);
CheckBoxList1.DataTextField = "Technology";
CheckBoxList1.DataBind();
}

View 1 Replies

DataSource Controls :: How To Create A LINQ DataContext Class As Per Database Design

May 5, 2010

I want to create a LINQ DataContext Class as per Database Design. I getting a problem in some cases.

the syntax to bulid a LINQ class :

[Code]....

Here Table Name Is HardCoded But I my case my Table Name A Changed as Finicial Year Change.So How I Give The TableName As RunTime

View 8 Replies

DataSource Controls :: SQLDataAdapter Postback / Create A Class, DataCommon, To Contain All SQL Data Manipulation Functions?

Apr 22, 2010

I'm trying to create a class, DataCommon, to contain all my SQL Data manipulation functions. I've created a Subroutine called Init that initializes a SQLDataAdapter:

[Code]....

From my other classes I am creating an instance of DataCommon, calling Init, and calling another subroutine in DataCommon that pulls data from SQL and loads the data into my dataset. This part is working great -- no problems at all. I'm loading three different Datatables in the Dataset with no issues.

At this point, I'll perform my various manipulations on the datatables -- add/delete/modify rows -- again with no problems. All of this is creating postbacks...and this is where my problem begins. After I've done all my manipulations to the data and am ready to update my SQL tables, I have to re-initialize my SQLDataAdapter. I thought I could do something like:
[Code]....

But I get the error: Exception inserting Class. Thread was being aborted.

In my initial data load from SQL, each datatable is getting loaded from a single SQL table, so I was hoping to use the autogenerated Update/Insert/Delete statements by the SQLDataAdapter. As a test, as soon as I filled the dataset initially, I added a new row to one of the datatables and used the SQLDataAdapter.Update() method before a postback occurred, and it worked perfectly.

So, with all that being said, I guess my question is, how do I reconnect the table mappings between my SQLDataAdapter and dataset to autogenerate the updates after a postback occurs? I've tried researching this, but I get confused after reading about FillSchema vs TableMappings vs everything else I've read about.

View 2 Replies

DataSource Controls :: ObjectDatasource And Class As Datasource

Jun 24, 2010

I am really having a hard time trying to write something from scratch I created a 'Person' Class.Public Class Person

Private _FirstName As String = ""
Private _LastName As String = ""
Private _Age As Integer = 0
Public Sub New(ByVal FirstName As String, ByVal LastName As String, ByVal Age As Integer)
FirstName = FirstName
_LastName = LastName
_Age = Age
[code]...

View 1 Replies

SQL Server :: SqlHelper.ExecuteNonQuery?

Aug 17, 2010

what is the use of this...?

View 4 Replies

'CreateDatabase.SqlHelper' Is Inaccessible Due To Its Protection Level?

Apr 9, 2010

I have create a class SqlHelper in window console client project, then test it it works fine. In my SqlHelper class I make all methods are public static. Then I created an assembly, add it to my unit testing project. Whne I try to access the public function of SqlHelper class, I got error like "Error 1 'CreateDatabase.SqlHelper' is inaccessible due to its protection level ".

Here is my class:

[Code]....

at this line: SqlHelper.setUpTestDatabase I got above error, Where goes wrong?

View 2 Replies

Forms Data Controls :: Create A Gridview In A Separate Class?

Feb 9, 2011

Does anyone know if it is possible to create a gridview from a class on a seperate webpage?

So I have webpage 1, that calls Class 1, in Class one there will be a Select Query that will call some info from a database and then return it to a gridview. The gridview wont work obviously as it is in the class and not on webpage 1.

Is there anyway to reference the fact I would like the gridview created on webpage1?

View 1 Replies

DataSource Controls :: How To Use DSN Using Web.config And Class

May 15, 2010

i am using,Asp.net(vb),database sql server 2005, i want to use sysdsn DSN for database connection,so please Guide me how do i use DSN using web.config and class(we have sqlhelper type our own DBclass to set connectionstring for whole applicatoin. which get connection string from web.config),

Now,how do i use/set dsn in this type of scenario.

View 3 Replies

SqlHelper.ExecuteReader Results Varying And Unexpected When Certain Number Of Records Are Returned?

Jul 4, 2010

Note: You may not need to read the whole thing to know what's wrong... skip down to the part about the 3 scenarios if you'd like. Only read the begin if you'd like some background info on how I've tried implementing this and where the errors occurred.To begin with, I'm trying to retrieve a list of Clients stored in the CRM_Clients table for a given callerId.I retrieve the clients from my Controller with the SelectLiveClientsForCaller method. The message is then passed on to the DAL through the static Instance method in the DataProvider class:

public List<Client> SelectLiveClientsForCaller(int callerID)
{
List<Client> results = new List<Client>();

[code]...

View 3 Replies

DataSource Controls :: Why SqlDataReader Class Is Not Instantiated

Feb 18, 2010

Why SqlDataReader Class object is not created by "new" Operator.

Is it not possible to create the object like below

SqlDataReader dr=new SqlDataReader();

dr=cmd.ExecuteReader();

Why the constructor of the SqlDataReader class is internal?

View 2 Replies

DataSource Controls :: Retrieving Records From DB Using SQL Class

Feb 3, 2011

When I used the (way #1) below I could retrieve search result from my DB

Way #1:

[Code]....

But When I use( way#2) "separating my code to Presentation layer and data access layer ( using SQL HELPER CLASS )"

Way # 2

Presentation layer: protected void btn_Search_Advance_Click(object sender, EventArgs e)

[Code]....

data access layer:

[Code]....

I keep getting this error: Procedure or function 'SP_Search' expects parameter '@SEARCHTYPE', which was not supplied.

View 6 Replies

DataSource Controls :: Pass Selectparameters To A DAL Class?

Mar 16, 2011

I have a webform whose ObjectDataSource reads an xml file to populate a GridView in the .aspx page. I have to hard code the file path in the .cs file defining the ObjectDataSource classes. I want to be able to use a portion of the query string to indicate which file to select, but, normal methods, like Server.MapPath and Http.Request.Current don't work in the class page. how I can pass values from the SelectParameters configured in the ObjectDataSource down to the ObjectDataSource method? Here is my Class code:

[Code]....

The filePath variable is what I want to be able to alter based on my query string.

View 1 Replies

DataSource Controls :: Can Not Reference Tableadapters From A .cs Class?

Apr 1, 2010

i've created a dataset, and created inside it a datatable and its table adapter.

when i try to reference the table adapter in a .cs class i get an error message that i'm missing some namespace:

Compiler Error Message: CS0246: The type or namespace name 'DataSet1TableAdapters' could not be found (are you missing a using directive or an assembly reference?)

View 2 Replies

DataSource Controls :: DB Wrapper Class For SQL Server And SQL?

Mar 4, 2010

Not sure if I'm posting in the right place so please forgive meI have an ASP.NET C# application that connects to either a SQL Server or MySQL database depending on some value that is set in my project config. The issue I'm trying to avoid is handling the connections and queries separately. Ideally I would want to use a DB Wrapper class that can handle both SQL Server and MySQL.

View 8 Replies

DataSource Controls :: SqlDataReader Class Is Not Instantiated By New Opperator?

Feb 19, 2010

When I am using SqlDataReader class on that time without creating instance of the SqlDataReader Class I m using Command.ExecuteReader() Method. Why We not create the object of the SqlDataReader Class by using " new " Operator.We use like below:

SqlDataReader dr=cmd.ExecuteReader();
Why not we use this class like below:

SqlDataReader dr=new SqlDataReader();

dr=cmd.ExecuteReader();

View 2 Replies

DataSource Controls :: Bulkcopy Class For Oledb Like Sqlbulkcopy?

Mar 17, 2010

I want to bulk insert the datatable data into database.I can not use sqlbulkcopy class.since,I am using oledb.

View 3 Replies

DataSource Controls :: Passing Parameters To Data Class

Apr 23, 2010

I have an ObjectDataSource3 that I am trying to use to insert data from:

From: Dropdownlist1.selected value To: (CustomerID)
From: Dropdownlist2.selected value To: (ProductCode)
From: txtTitle (Title) To: (Title)
CurrentDate To: DateOpened
The btnAdd event is suppose to calls:
ObjectDataSource3.Insert()

Below is my code for both the page and class. Although my class is expecting parameters, I don't know how to get the parameters to the insert function in my class.

[Code]....
[Code]....

View 2 Replies

DataSource Controls :: EntityFramework Base Class Inheritance?

Feb 11, 2010

I am having some issues with my base class inheritance. I am currently employing Table per Type Inheritance for the following tables:

Database:

Members Table

- Member ID (PK)

- First Name

- Last Name

- Email

- ...

Students Table

- Member ID (FK)

- Credits

- Notes

- ...

Instructors Table

- Member ID (FK)

- Biography

- Office Hours

- ...

My Entity Data Model defines "Member" as the base class for both Students and Instructors, since members can be both students as well as instructors simultaneously. The problem, however, occurs when I attempt to get a list of Members objects. Because the database contains members who are indeed students AND instructors, the following exception is thrown:

All objects in the EntitySet 'CountyCollegeEntities.BaseMembers' must have unique primary keys. However, an instance of type 'CountyCollege.NET.Administrator' and an instance of type 'CountyCollege.NET.Student' both have the same primary key value, 'EntitySet=BaseMembers;ID=10016'.

I am beginning to think that I made a mistake by building these classes to inherit from Member although it has been ideal up until this point. But before I start ripping up all my existing code to remove this inheritance, I thought I would see if anyone has any tricks that would make this work. Any advice as to either how I can get around this error or a more appropriate way to structure my classes would be very much appreciated.

View 2 Replies

DataSource Controls :: While Adding LINQ To SQL Class - Empty Use Option

Feb 4, 2010

I am new to LINQ but not >net. I do understand SQLDataSource, etc. I was just told by a coworker not to use a LINQ to SQL Class for my new project (Bank.dbml). I was told to use instead the ADO.Net Entity Data Model (bank.edmx).

BankModel.edmxBank.dbml

When only using ADO.Net Entity Data Model I try to associate a GridView with a new LinqDataSource I get no options. When I add a LINQ to SQL Class I get the option to use it but it is empty. Is this because all my LINQ classes are mapped in the ADO.Net Entity Data Model (bank.edmx)? Can someone tell me (or point me to) what the differences are in these two?

View 4 Replies

MVC :: How To Create A Class For Every Form Create

May 19, 2010

Should we create a class for every form we create,that will us to do the validations etc etc?

View 1 Replies

DataSource Controls :: Access Layer - Northwind Tutorial - Unable To Find The NorthwindTableAdapters.ProductsTableAdapter Class

Mar 31, 2010

I've been attempting to walk through the "Creating a Data Access Layer" tutorial found [URL] I create the DB connection, create the typed dataset and table adapter, specify the sql, etc. When I add the code to the presentation layer (in this case a page called AllProducts.aspx) I am unable to find the NorthwindTableAdapters.ProductsTableAdapter class. I tried to import the NorthwindTableAdapters namespace, but it is not showing up. Looking in the solution explorer Class View confirms that there is a Northwind class, but not the namespace I'm l ooking for. I've tried several online tutorials that all have essentially the same steps, and I'm getting the same results.

View 1 Replies

DataSource Controls :: Linq To Entities - Multilevel Projection Into Business Class And Not Breaking Deferred Execution?

Mar 18, 2010

I have a problem. (this a simplfied example)

In Entity framework I have a class which is effectively

fooEntity
{
public Guid Id {get; set;}
and a collection of fooChildEntity
}
a fooChildEntity is again an entityframework class
fooChildEntity
{
public Guid kidId {get; set;}
}

Now I also have a pair of business layer classes foo and fooChild

foo
{
public Guid Id {get; set;}
ilist<fooChild> Children {get;set;}
}
fooChild
{
public Guid kidId {get; set;}
}

My aim is to write a linq to entites that will allow me to convert the entity foo and children into the business foo and children without breaking deferred execution ( I will be adding filters to reduce the recordset at a higher coding level in the business layer)

doing something like

this.context.fooEntity

.include(fooChildEntity)

.Select( fe => new foo { Id=fe.Id ,

fe.foreach(fec => Children.add( new fooChild { kidId = fec.kidId}))})

.AsIQueryable()

is plainly rubbish and would never compile - it is however an indication of the direction I was thinking .

Even if I got a foreach to work like that or similar it would break deferred execution

At this point there are around 300,000 foo entities which I will eventualy filter to 5 or 6 foo's - this is why deferred execution is needed.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved