.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 27th, 2004, 11:31 AM
m3ckon m3ckon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Sheffield UK
Posts: 69 m3ckon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 57 sec
Reputation Power: 6
Which .NET database control to use?

Hi there,

I'm relatively new to .net and am currently migrating several asp sites to asp.net

I'm a bit stuck though on one of the pages I'm trying to create.


I need to establish a connection to a database and show all records that meet a certain criteria ... I was going to display them using a datagrid.

However on the page, I need a text box with a button which will then run a query ... probably from a stored procedure. This query will alter the data that is displayed in the datagrid.

I want the data in the datagrid to update itself. My questions are:

1) How easy is this to do? (I think very but I may be wrong)

2)Should I be using a datagrid or should I use a repeater or even a datalist?

3) what are the differences between these controls?

Thanks

M3ckon

Reply With Quote
  #2  
Old February 27th, 2004, 03:24 PM
fetcher fetcher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Portugal
Posts: 106 fetcher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 11 m 33 sec
Reputation Power: 6
Hi, it is very easy to do that. I'm not going to type much code I'll just give you directions.

Assuming you want the data to be populated to the control when you load the page for the 1st time:

in Page_Load:
Code:
if(!IsPostBack)
{
    //A procedure to get the data
    BindData()
} 

in the BindData procudure you get the data from the database and bind it to the control

Now to run a query..just populate the control in the button click event

Code:
private void btnSearch_Click(object sender, System.EventArgs e)
{
    // here call the stored procedure with the textbox
   // parameter and bind the result to the control
     
    //call ur Stored procedure
    // put the result in a dataset
    // yourRepeater.DataSource = yourDataSet;
   //  yourRepeater.DataBind();
}


and that's it.


Differences between controls... in a very simple way, the datagrid has lots of features and you should only use it if u need editing, sorting and so on. The repeater is very simple and the fastest one, suitable for listings. In your case I would use a repeater.

I hope my english was clear enough because I am in a hurry

Reply With Quote
  #3  
Old March 1st, 2004, 09:44 AM
m3ckon m3ckon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Sheffield UK
Posts: 69 m3ckon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 57 sec
Reputation Power: 6
Thanks Fetcher,

I'm almost there I think .. I used the SqlConnection and the SqlDatareader onPageLoad and I bound the SqlDatareader to the repeater control.

For the input box, I run some code when a button is clicked that runs my stored procedure. The stored procedure updates one row, and does not return a recordset.

If I refresh the page, the record will update, so my code is working. My question now is how can I update the repeater control .. can I call the onpageload code from my buttonclick code?? or is there a better way of doing this??

M3ckon

Reply With Quote
  #4  
Old March 1st, 2004, 11:35 AM
fetcher fetcher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Portugal
Posts: 106 fetcher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 11 m 33 sec
Reputation Power: 6
put the code you are using in onpageload to bind the repeater in a separete function then call that function from onpageload and from buttonclick

Reply With Quote
  #5  
Old March 1st, 2004, 12:08 PM
m3ckon m3ckon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Sheffield UK
Posts: 69 m3ckon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 57 sec
Reputation Power: 6
Quote:
Originally Posted by fetcher
put the code you are using in onpageload to bind the repeater in a separete function then call that function from onpageload and from buttonclick


I just added Call Page_Load to my button function and it worked a treat

I've now got to get a stored procedure to run a dts on SQL Server and all will be completed. Thanks for your help, this seems a lot better than ASP IMHO

Reply With Quote
  #6  
Old March 1st, 2004, 06:10 PM
fetcher fetcher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Portugal
Posts: 106 fetcher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 11 m 33 sec
Reputation Power: 6
no problem. Yes I also think it is a lot better than ASP or any script language. It can be a little frustrating in the beginning because it takes time to get used to it but once you learn and "tame" it you won't look back

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > Which .NET database control to use?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT