.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Traversing DB Tables

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :ASP.Net
Hi folks,I read some articles before posting to try and solve my issue but i didn't get anywhere, your input is highly appreciated. Here is what i'm trying to do:1) I have an excel sheet with 1 EntrantID column and the rest are numbers (these numbers refer to answer codes for certain questions),So for example, my excel sheet looks something like:ID --- a1 --- a2 --- a3 --- a4 --- a5 --- etc...1 ---- 32 --- 55 --- 12 --- 121 -- 50---etc...The goal is to traverse thru every row, and every column and according to a checking condition for the values of answers, i will add the number to one of two columns in another table, so for example, i will start traversing a1, i will check it's value which is 32, if 32 > 0 and 32 < 60, then i will add 32 to columnA in another table, else, i will add it to column B in that table, then i will move on to the next value, a2 which is 55, it's < 60 so i will 'add' it to that same columnA in that table..At the end, my other table, the one with results should look like this:PersonID --- columnA --- columnB1 ------------ 32, 55, 12 --- 121, 50Hope i didn't confuse things, i'm trying to explain as best as i can lol.So what i did, i imported the excel sheet to sql server, and i looked up SQL language to see if i can do that thru SQL itself, and i couldn't find a way to traverse columns, so next, i started an A

View Complete Post

More Related Resource Links

MS SQL Server: Search All Tables, Columns & Rows For Data or Keyword Query

If you need to search your entire database for specific data, this query will come in handy.

So when a client needs a custom report or some sort of custom development using Great Plains, most of the time I will have to track down the data in the system by running this query and find the table(s) it is in.

Temporary Tables - MS SQL Server

Usage of temporary tables in MS SQL Server is more developer friendly and they are widely used in development. Local temporary tables are visible only in current session while global temporary tables are visible across all sessions.

Temporary tables in SQL Server vs. table variables

When writing T-SQL code, you often need a table in which to store data temporarily when it comes time to execute that code. You have four table options: normal tables, local temporary tables, global temporary tables and table variables. I'll discuss the differences between using temporary tables in SQL Server versus table variables.

Using a trigger or anything else to populate two tables


Hi! I'm creating an application that's supposed to first add a record to table1, and then get the ID from that record to use when adding a record to table2, to be able to associate these two records with eachother.

The user gets to type in some values that goes to table1, and some values that goes to table2, but before the insert statement for table2 is executed i need the ID from the recently added record in table1. Some dude told me to use a trigger for the autopopulate purpose, but does that really work when i also need to save some values that's user input, and when those values doesn't get saved in table1?

Are there any other way to do this or can i send values to a trigger? I'm new to triggers and stored procedures, i don't have any particular knowledge of this, any help is appreciated!


Regards, Monsterbadboll

merging multiple tables in a single dataset to single table


 i have a stored procedure which returns three tables to a dataset ..... now i need to merge all three tables to a single table from d same dataset 

like dataset1 has table1 table2 and table3 .... i want all the three tabels to be merged into dataset1 itself .... instead of three diffrent tables so that i can show all three table data in a single datagrid  as a compact data and combination of 3 tables from d single dataset.....

can some1 help me please.....

SqlDataSource UpdateCommand using 2 tables


I have two tables

Trans  with fields TransID, Date, CustomerID and some other stuff

Customer with fields CustomerID, Name, TaxId

On the screen the user only sees the fields Date and Customer Name. CustomerID is behind the scenes only.


I'm using SqlDataSource. Having no problems with SelectCommand. I don't know how to construct the UpdateCommand and InsertCommand.

Let's say the user changes the date, then I need to do an UPDATE.

UPDATE Trans SET Date = @Date, CustomerID = @CustomerID results in an error message and the record is not updated.

I get an error on the page that says "Sys.WebForms.PageRequestManagerServerErrorException: Input string was not in correct format".


I tried taking out the set for CustomerID and I still get the error on page.


Also, for inserting, the users will see a dropdownlist with Customer Names. I need to convert that to a CustomerID to be used in the new record being inserted in the database. I'm not sure how to do this.


Do I need to do something with Control Parameters?

How to display related tables in one crystal report and how to link this report with combobox?


Hi! I want to display a crystal report in my vb.net application. Suppose I have tables named student details, student marks, student address, etc... Now if I want to display all these details (fields of all tables) in one crystal report (with page breaks if necessary) then how will I achieve it. I will be providing a combo box in my application that contains list of student names. How can I link this combo box with the cystal report to dynamically display report for different student on selected index change of combo box? Help me friends. An example would be appreciable.

Data Points: Creating Audit Tables, Invoking COM Objects, and More


Dealing with error handling between T-SQL and a calling application, evaluating when a field's value has changed, and creating auditing tables in SQL ServerT are all common issues that developers must tackle.

John Papa

MSDN Magazine April 2004

Sql Scripts - Delete all Tables, Procedures, Views and Functions


In a shared environment you typically don't have access to delete your database, and recreate it for fresh installs of your product. 

I managed to find these scripts which should help you clean out your database.

Use at your own risk.


Delete All Tables

--Delete All Keys


Join Two Tables and Prepare Report



            I have a select query which is executing well. Now, I want to add one more field to that query. That field is not in the current query table, It is in the another table.

How do I join those two tables and get that field value in the existing select query.?


Migrating aspnet tables to dev server - having issues



We're trying to migrate a one of our apps to our dev server for testing and development, but we're having problems with the membership functionality. We can add users, but there seems to be a disconnect with roles. We can query the aspnet_users table and find the new user in there, but when we query the aspnet_usersinroles table, that user id is not present.

We're also unable to run the Roles.GetUsersInRole("somerole") method. It returns 0 records. When I run Roles.ApplicationName, it returns the correct name, so .NET should be passing the correct app name.

We're just a little baffled. If anyone could shed some light on what could be the issue, we would appreciate it.

Thanks! :)

Uploading to SQL Server using AJAX muiltiple file uploader and dynamic SQL Server Tables


I am getting an error on the following code when trying to pload files directly to a database.  

 Incorrect syntax near ','.

 Incorrect syntax near 'image'.


    Private Sub Uploader_FileUploaded(ByVal sender As Object, ByVal args As UploaderEventArgs)

        Dim data() As Byte = New Byte((args.FileSize) - 1) {}

        Dim stream As Stream = args.OpenStream

        stream.Read(data, 0, data.Length)

    End Sub


Private Sub ButtonTellme_Click(ByVal sender As Object, ByVal e As EventArgs)


        Dim objConn As New SqlConnection("Data Source=mrpoteat.db.2798093.hostedresource.com; Initial Catalog=mrpoteat; User ID=mrpoteat; Password=Colgate23;")


        Dim strCommandText As String = ""

        For index = 1 To Attachments1.Items.Count Step 1

            strCommandText += "pic" + index.ToString() + Space(5)

Help needed in selecting coulmns from 2 tables using entity framework


Hi all,

I have two tabels as mentioned below. I am using entity framework and vs2010.I am not able to write linq query to get data from both the tables. there is one to many relationship(for one category ther can be multiple articles). Please help me out as this is very urgent. Thanks in advance.

1) Article

ArticleID bigint Unchecked
CategoryID int Unchecked
ArticleName varchar(500) Unchecked
ArticleDesc nchar(1024) Unchecked

Event Hanlder to update other SQL tables



I'm writing a small app to allow viewing and editing of a single SQL table (the _Assets table).

I have a form-view that allows the data to be viewed (ItemTemplate) and edited (EditItemTemplate).

Everything works well. All the SQL editing is done in the Mark-Up using a simple SqlDataSource, asp:Parameters and data-binding, (ie. there is no VB code behind).

However, I need to write an event-handler which updates other tables when the EditItemTemplate INSERT button is used.

This event handler needs to update OTHER SQL tables.

The idea is to create a HISTORY of changes (Updates) made to my _Assets table.

It would look something like this:

IF the value of the _Assets.Comments field is changed by the formview, then:

Open SQL connection to _CommentsHistory table

Update _CommentsHistory

SET CountrySerial = asp:Parameter Name "CountrySerial" from SqlDataSource ID="FindAsset"

SET OldComment = [the original Comment] asp:Parameter Name "Comments" from SqlDataSource ID="FindAsset"

SET NewComment = [the New Comment inserted in the formview] TextBox ID="CommentsTextBox" from FormView ID="FormView1"

SET ChangeDate = { fn (now)}

Set ChangedBy =

SqlDataAdapter.Update related tables



I would like to get 2 related tables from SQL Server to DataSet, insert new rows and save them back to SQL Db.

Let's say i have 2 related tables as shown below...

Table1 Table2
test1ID (Primary Key) test2ID (Primary Key)
data test1ID


In Sql i have Diagram with relationship and Update Rule is set to Cascade

I am trying to get them to dataset, insert "master" and "child" row and save them back to db.

I tried different approaches (none of them workes) and this is one of them:

Dim ds As New DataSet()
        Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("NastanitveConnectionString").ConnectionString)
        Dim sql As String = "SELECT * from Table1;Select * from Table2;"
        Dim d

InfoPath and Access - two parent tables and one child table


Hi there,

I'm trying to link an InfoPath form to an Access database, I want to connect the InfoPath form to 3 tables in the Access database but InfoPath will only recognise parent-child relationships in a series (e.g. the "Company" table is the parent to the "Customer" table, which is again parent to the "Orders" table)

I need to have two parent tables and one child table, though (e.g. "Customer" is parent to "Orders", but "Inventory_Item" is also parent to "Orders"). Is there any way to establish this in InfoPath? I'm using Windows XP, InfoPath 2007 and Access 2007.

Cheers, Patrick

Tables not showing in Management Studio Express


Hi all

(needing help!)

Have used Visual Web Developer 2008 to make ASP application, with SQL server 2008 R2 Express for database. Works very nicely.

However, when I come to use Management Studio Express 2008 R2, I cannot see all my tables.

The ones I CAN see were created by the MS script that creates membership tables (and are called dbo.aspnet_membership etc), presumably because the owner of the tables was specified as 'dbo'.

The ones I can't see from Management Studio are the ones I created. I never specified an owner.

I think this is a permissions issue, but I can't fathom it. There's only ever been me on my development machine (laptop) doing it all, hence always the same log ins.

Running Management Studio as Adminstrator doesn't help.

I can't even ask Management Studio who own's the tables that I can't see because Management Studio can't see them so rejects the script.

Any ideas/links very (very) welcome !


**** Actually, it is even wierder. The tables in Management Studio have full structure, but are empty. But if I look at them in Visual Basic 2008 they are full !!!  And...if I create a table in Management Studio it does not appear at all in Visual Basic, and likewise, a table created in Visual Basic does not appear at all in Management

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend