473,387 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Gridview without using sqldatasource

103 100+
Hi all,

I would like to connect gridview with database without using sql datasource..

I am using sql server and c#.net..

Please help me..

regards,
Mathew.
Oct 1 '07 #1
3 5337
Plater
7,872 Expert 4TB
You can create DataSets and DataTables that can be used as the datasource for gridview.
Create an sql connection
Create an sql query string (i.e. string myq="SELECT * FROM myTable")
Create an empty DataTable or DataSet
Create an sql dataadapter
use .Fill() of dataadapter to fill datatable/dataset
Assign the gridview's datasource to the datatable/dataset
Oct 1 '07 #2
mathewgk80
103 100+
You can create DataSets and DataTables that can be used as the datasource for gridview.
Create an sql connection
Create an sql query string (i.e. string myq="SELECT * FROM myTable")
Create an empty DataTable or DataSet
Create an sql dataadapter
use .Fill() of dataadapter to fill datatable/dataset
Assign the gridview's datasource to the datatable/dataset
I would like to implement 3 tier also..

Can you give me an example?
Oct 1 '07 #3
sijugeo
42
The three tiers are 1. Presentation Layer,2. Business Layer,3. Databaselayer

you can write the code for connection to database in the DB layer like this

string connstring = "Data Source=Databaseaddress; Initial Catalog=Database; User Id=something; password=something";
SqlConnection conobj = new SqlConnection(connstring);
SqlDataAdapter da = new SqlDataAdapter("select * from Employee", conobj);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;

In the presentation layer:
GridView1.DataSource = bl.gridview();
GridView1.DataBind();

Make the return type of the function as dataset or datatable.

Then make an object for the dal class. and use it in the BL. Make an object for Bl in the presentation layer and assign it into the gridview..

Regards,
Siju.
Oct 4 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
6
by: Dabbler | last post by:
I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to an SqlDataSource, then have a value from a boundfield in the row be passed as the keyfield for select where clause. Im...
5
by: yefei | last post by:
In my web design, I display records from a SQL DataBase according to some filters the GridView is defined with select commands and selest parameters however, I also want to display all records...
0
by: Mike P | last post by:
Where exactly are the updateparameters of a gridview picked up from? I have created 2 very similar gridviews and given the updateparameters the same names as in my edititemtemplates. Yet this...
2
by: MRW | last post by:
Hello! I don't know if this is possible, but I have two tables in a one-to-many relationship. I want one record to be displayed in a GridView from table1 with a blue background, followed by all...
4
by: Mike | last post by:
I'm having trouble getting a gridview to bind. I probably missing something completely obvious and would appreciate any help on offer. I'm passing parameters via querystring, and have created a...
4
by: Tomasz Jastrzebski | last post by:
Hello Everyone, I have a GridView control bound to a plain DataTable object. AutoGenerateEditButton is set to true, Edit button gets displayed, and RowEditing event fires as expected.
0
by: LiamLiamLiam | last post by:
G'day all. I having a problem with my formview. I'll ty to explain my situation as best as i can. I have a page with a search field at the top which is just a simple asp:textbox. Below that i...
4
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.