|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 ![]() |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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
|
|
#5
|
|||
|
|||
|
Quote:
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 |
|
#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
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > .Net Development > Which .NET database control to use? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|