Tuesday, March 13, 2012

So how do i databind?

Since you have no bindingsource adapter.
I want to have a page with controls that are binded to each other.
Where do i start from?
Do i use sqldatasource do i use SqlDataReader?
Must i bind a dataset to the control or a datareader?
I'd appreciate a general guide.
Also any particular reason that this does not work (displays nothing,although i have 4 rows in my table)

Dim com As SqlCommand
Dim adapter As New SqlDataAdapter
Dim sql As String

sql = "SELECT * FROM dbo.UserJobs"

Dim con As SqlConnection = New SqlConnection("server=(local);" & _
"database=Ag_Test;Integrated Security=SSPI")

con.Open()

com = New SqlCommand(sql, con)

Dim read1 As SqlDataReader = com.ExecuteReader()


FormView1.DataSource = read1
FormView1.DataBind()

con.Close()Most likely because you haven't set up any templates in the FormView. To start with, substitute the FormView with a GridView.

GridView1.DataSource = read1
GridView1.DataBind()

Of course, you'll need to place the gridview on your page.

You would ideally use a datareader or a dataset's table in such a situation. A FormView most likely requires a template to display the information while a gridview will simply display the information in a table format.
No i haven't set any templates and i don't know how to use them but i'll look them out. Must i use datasets or sqldatasource? I see very different properties for each one. Well i'll have a read on sqldatasource cuz i've never used something like this.

The problem i'm facing is that i'm used to strandart .NET and i have some problems.
I want for example to write my Fillby queries under my dataset tables in designer and use them but there is no dataset designer! It reminds me all little of the old VS2003.
Anyway that's me blabbering, thanks for the advice, any xtra comments are very welcome.
I didn't understand that very well. Fillby queries? Sounds like a donut company :afrog:

Anyways, there are two 'paths' you can take. There is the simpler path which involves SqlDataSources, which you can drag onto a form, configure and bind your controls to. These are meant for simple queries, simple applications. The other path is using handcoded ADO.NET, where you create a dataset and bind it to a control. You get more flexibility this way and it is scalable.

Although this thread (http://www.vbforums.com/showthread.php?t=466658&highlight=introduction+ado.net) is for windows forms, you will be able to get a feel of ADO.NET from it, using datasets. You can then apply that knowledge to your ASP.NET applications.
Yes fillby queries is a Record Company :D
Actually in 2005 you can go to the data designer and there you can see your datatables if you add a query there you usually name it "fillbyXXX" thus fillby queries.
Actually i know a fer amount of ADO(and DAO) but i could not do anything since i wanted to databind a formview and all i got was a white screen. So you told me about templates but i haven't tried anything yet.
ASP is kind of different from .NET and i got pissed that i could not even bind a simple object.I'll get over it.

So any advice on where to start? In assumption that i know .net. Must i learn html?
Gridview, dude. Try that first. Place a gridview on your page, then use the code I gave above.

As to where you can start, first thing to do is to clear your mind of ASP. ASP is not even closely similar to ASP.NET, they just have the same name. The same goes for VB6 and VB.NET.

Next, tutorials. Even though you know ADO.NET, it's best to put it to practice to get a feel of how to do things. Look at the thread I gave you in the post above. Also, look at ADO.NET QUickstart tutorials.

http://samples.gotdotnet.com/quickstart/howto/doc/adoplus/ADOPlusOverview.aspx

Version doesn't matter, it'll work in .NET 1.1 and 2.0.

That done, you can then come back and try what you're trying.
Sorry i forgot to thank you :)
No problem, remember to postback (that's my favorite pun) when you have another question.

0 comments:

Post a Comment