Showing posts with label VisualWebDeb. Show all posts
Showing posts with label VisualWebDeb. Show all posts

Display Record Values from Two Tables in ASP.net Visual Web Developer Express Edition

To display data from two tables in ASP.net, we’ll need two tables with one or more identical fields. One field should act as a primary key on one table and the other should act as a foreign key or normal key on the other table. For the sake of example, let’s make two tables tblStudents and tblBooks using the following structures:

a. tblStudents
Column NameData Type
chrstudidnchar(10)
chrstudfnamenchar(20
chrstudlnamnchar(20)

b. tblBooks

Column NameData Type
chrbookidnchar(10)
chrtitlenchar(30
chrauthornchar(30)
chrstudidnchar(10)

1. Start Visual Web Developer Express Edition.

2. Click File>New Website>Select Asp.net website from Visual Studio Installed Templates options>Click Ok.

3. Click View>Solution Explorer>Right-click App_Data from the solution Explorer>Add New Item>Select SQL Server Database from Visual Studio Installed templates options>Accept the default database.mdf name>Click Add.



4. The Database Explorer panel will then come into view. To create a new table>Right-click Tables from the database explorer panel>Select Add new table.



Enter the following column names, use chrstudid as a primary key:



5. Click the close(x) button when done. You will be prompted if you wanted to saves changes to the table, just Click the Yes button>Enter “tblStudents” in the Enter a name for the table textbox>Click Ok.

6. Click the + icon beside the Tables node in the database Explorer>Right-click tblStudents>Click Show Table Data.



Enter the following values:




7. Right-click Tables from the Database Explorer again then Select Add New Table.



Enter the following Column names using chrbookid as a primary key:





8. Click the close(x) button when done. You will be prompted if you wanted to saves changes to the table, just Click the Yes button>Enter “tblBooks” in the Enter a name for the table textbox>Click Ok.

9. Click the + icon beside the Tables node in the database Explorer>Right-click tblBooks>Click Show Table Data.



Enter the following values:



10. Click View Solution Explorer > Double-Click Default.aspx> Double-click the design button>Expand the Data category of the toolbox>Click and drag a SqlDataSource control to the Outline Designer window.



11. Click the configure data source link>Select Database.Mdf from the “Which data connection should your application use to connect to the database?” listbox>Next.


12. Click the Specify a custom SQL statement or stored procedure radio button>Next.

13. Click the SELECT tab then enter the following SQL statements in the SQL Statement textarea:



14. This statement retrieves the values of our specified column names from both tables. If you noticed, we’ve added tblStudents dot chrstudid to specify that the values should be retrieve from the tblStudents table since tblBooks table also has chrstudid.Moreover, we’ve added INNER JOIN to join our tables using a common field
due to the fact that chrbookid, chrtitle, and chrauthor exists on the other table.


15. Click next. You can click the test query button to preview the result then click the finish button.

16. Click a grid view control from the data category of the toolbox then drag it onto the Outline Designer. Select the name of your SQLDataSource from the gridview’s Choose Data Source List Box.



16. Press CTRL + F5 to test your application.

17. You should now see an output similar to the following screenshot:

Fixing the "No value given for one or more parameters" in Visual Web Developer 2008

This error normally appears when you have selected enable deleting and enable editing GridView or FormView task options and you try to delete or update a record at run-time. This error can be fixed by converting the SQL statements in the InsertCommand and AccessCommand to Jet SQL statements. To be able to clearly understand the solution, let us start from the beginning:
1. Create a database file in Ms-Access and name it “dbNames”. Make a table inside it and name it “tblEmployee” using the following specification:

2. Don’t forget to click yes when you will be ask to create primary key, otherwise you will not be able to add an Edit or Delete buttons to your grid view control.
3. Add appropriate values to your table, for instance:

4. Click Start>All Programs>Visual Web Developer 2008.
5. Click File>New Website>ASP.net Website>Ok.
6. Click View>Solution Explorer>Right-click your website solution name, Select Add Existing Item. Locate you dbnames access database file>Add. The solution explorer should now look like this.

7. Click the design tab then add a GridView control to your form.
8. In the Choose data source listbox, select new data source>Select Access database>Click the browse button>Select dbnames>Ok>Next>Click the * checkbox from the columns category>Click the advance button>Click the Generate Insert, Update, and Delete statements checkbox including the Use Optimistic Concurrency checkbox>Ok.
9. Click Next. Click test query to view the result of the sql statement then click finish.
10. Click the GridView task button(>) then check enable paging, enable sorting, enable editing, enable deleting, and enable selection checkboxes.
11. Click the View in Browser button. If you are prompted to save changes to your website, just click the yes button.
12. If you try to click or update a record value now, you will be taken to the following to a screen containing the following message:

13. To solve this problem, click the Source tab to view the source code of your website. Look for the following lines:

14. Delete the OR logical operators including its respective conditions, your code should now look like this:


15. Click the View Browser button and try clicking the Deleting or Record value. This time you can delete or delete a record value without getting a ““No value given for one or more required parameters”