473,385 Members | 1,620 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,385 software developers and data experts.

C# Data Binding

karenRoss
I'm trying to bind my repeater control to a SQLCommand Object...but I dont think I'm anywhere close...


Expand|Select|Wrap|Line Numbers
  1. myConnection.Open();
  2. Repeater1.DataSource = searchCommand.ExecuteReader(CommandBehavior.CloseConnection);
  3. Repeater1.DataBind();
  4.  
Jun 6 '07 #1
3 1447
nateraaaa
663 Expert 512MB
The DataSource property will load the Repeater control with data. What you need to do is run a stored procedure to return rows of data then fill this data into a dataset. Then use a dataset as the datasource of your repeater.

Try this.
Expand|Select|Wrap|Line Numbers
  1. DataSet ds = new DataSet();
  2. connection.Open();
  3. SqlCommand oCmd = new SqlCommand();
  4. oCmd.Connection = oConn;
  5. oCmd.CommandType = CommandType.StoredProcedure;
  6. oCmd.CommandText = "nameofyourstoredprocedure";
  7. ds.Clear();
  8. SqlDataAdapter oDataAdapter = new SqlDataAdapter();
  9. oDataAdapter = new SqlDataAdapter(oCmd.CommandText, connection.ConnectionString);
  10. oDataAdapter.SelectCommand = oCmd;
  11. oDataAdapter.Fill(ds);
  12.  
  13.  
  14. Repeater1.DataSource = ds;
  15. Repeater1.DataBind();
This should get you on the right track.

Nathan
Jun 6 '07 #2
The DataSource property will load the Repeater control with data. What you need to do is run a stored procedure to return rows of data then fill this data into a dataset. Then use a dataset as the datasource of your repeater.

Try this.
Expand|Select|Wrap|Line Numbers
  1. DataSet ds = new DataSet();
  2. connection.Open();
  3. SqlCommand oCmd = new SqlCommand();
  4. oCmd.Connection = oConn;
  5. oCmd.CommandType = CommandType.StoredProcedure;
  6. oCmd.CommandText = "nameofyourstoredprocedure";
  7. ds.Clear();
  8. SqlDataAdapter oDataAdapter = new SqlDataAdapter();
  9. oDataAdapter = new SqlDataAdapter(oCmd.CommandText, connection.ConnectionString);
  10. oDataAdapter.SelectCommand = oCmd;
  11. oDataAdapter.Fill(ds);
  12.  
  13.  
  14. Repeater1.DataSource = ds;
  15. Repeater1.DataBind();
This should get you on the right track.

Nathan
Thank you so much. I'd buy you a cappuccino (from some independent shop, not starbucks) if I could.

I'm so glad you were on the internet today ;)
Jun 6 '07 #3
Plater
7,872 Expert 4TB
You can use DataSets (and maybe DataTable)
Expand|Select|Wrap|Line Numbers
  1. DataSet retval= new DataSet();
  2. string myq="SELECT ...";//your sql statement
  3. SqlDataAdapter dba = new SqlDataAdapter(myq, dbcon);//dbcon is my SqlConnection object
  4. dba.Fill(retval);
  5.  
Jun 6 '07 #4

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

Similar topics

0
by: Ann Morris | last post by:
INTRODUCTION One of the most powerful aspects of .NET and Windows Forms is data binding. Data binding is the process of associating user interface (UI) elements with a data source to generate a...
16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
1
by: matty.hall | last post by:
There's a lot of information out there about data-binding UI objects (i.e. derived from Control) to non-UI custom business objects. Is it possible to do the same without any UI being involved at...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
19
by: Simon Verona | last post by:
I'm not sure if I'm going down the correct route... I have a class which exposes a number of properties of an object (in this case the object represents a customer). Can I then use this...
19
by: Larry Lard | last post by:
In the old days (VB3 era), there was a thing called the Data Control, and you could use it to databind controls on forms to datasources, and so (as the marketing speak goes), 'create database...
0
by: mjsterz | last post by:
I've been working with VB .NET for less than a year and this is the first time I've posted on one of these groups, so let me apologize beforehand if I'm being unclear, not posting my issue...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
3
by: Max | last post by:
Hello, I made a windows form with a combo box and 4 text boxes. All 5 objects should get their data from a data set which is populated in the form load method. The combo box has item ids. When...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.