Showing posts with label displaying. Show all posts
Showing posts with label displaying. Show all posts

Friday, March 23, 2012

Help on Displaying Data from sqldatasource as Microsoft SQL Server (SQLClient)

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NWHCConnectionString %>"
SelectCommand="SELECT * FROM [AI_news]" OnSelecting="SqlDataSource1_Selecting">
</asp:SqlDataSource>

This is my code, I have followed the wizard perfectly the way its supposed ot be, well not 100% perfectly. This is how its supposed to be. When using a XXXX.MDF file I could use the wizard and it works fine. I do not know why my above code won't work. I am connected to the database and can view code manually. but not on a aspx page.

i am using master page, now trying to add this into default.aspx

Any help will be appreciated. I am currently losing some hair.

How are you trying to display the data? Have you bound a GridView to the SqlDataSource control? If not, add this:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True" DataSourceID="SqlDataSource1"></asp:GridView>

|||

I forgot to add a few things,

I am using Microsoft SQL Server (SqlClient).

with this code

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NWHCConnectionString %>"
SelectCommand="SELECT * FROM [AI_news]" OnSelecting="SqlDataSource1_Selecting">
</asp:SqlDataSource>

The code below compile fine, but doesn't show any results.

When I use Mikesdotnetting code, I receive this message.

The DataSourceID of 'GridView1' must be the ID of acontrol of type IDataSource. A control with ID 'SqlDataSource1' couldnot be found.

Lastly, I did not add anything in my webconfig file.

I will be working on this page while waiting for support.

|||

You need both on the page at the same time. The SqlDataSource only fetches the data. The GridView is what displays it.

I suggest you take the time to acquaint yourself with the basics. http://www.asp.net/learn/

Drag, drop and fingers crossed won't get you very far.

|||

What I am trying to do here is to display whatever information that is necessary to work from the database. I want to see if the data would at least work, I do not see any data displayed yet regardless how its displayed.

I will look into the tutorials


Friday, March 9, 2012

help needed for 2 tables

hi everyone, i've added 2 tables one is on adding, the other one is on returning. but when i return, the dropdownlist keeps displaying those which are returned already. it shouldnt display because i've already returned.

here are the codes that i add,

"INSERT INTO record VALUES( '" + dateOfIncoming + "', '" + manifestNo + "', '" + hoName + "','" + hoRemarks + "', '" + toName + "', '" + toRemarks + "', '" + purpose + "', '" + timeEntered + "', '" + dateEntered + "', 'Out')"

here are the codes that i return

"INSERT INTO returnRecord VALUES( '" + dateOfIncoming + "', '" + manifestNo + "', '" + hoName + "','" + hoRemarks + "', '" + timeEntered + "', 'In')"

here are the codes that i wanna display in the dropdownlist which i have set the status = IN. means they have returned already so it should display.

this is wad i tried what its wrong -->

"select a.manifestNo from record a, returnRecord r where a.status = 'Out' And r.status = 'In'"

my dropdownlist cant retrieve those records that are already returned. i suspect is the select statement that is wrong. but i cant figure out how. please help me!

regards, ethan

Instead of using inline SQL you really should use stored procedures, if you rewrite these as stored procedures you will be able to test them more effectively in sql management studio. Are you trying to sleect manifestNo from both tables, i think the error lies around returnecord r - you are specifiying the table but the select.