Observable Collections
page 4 of 9
by frans eilering
Average Rating: 
Views (Total / Last 10 Days): 40663/ 54

The database

Create the table

In the SQL database, create the contact table

Go to your database and insert a new stored procedure.

Copy the code below in this procedure and click the "Execute" button.

Code for creating table Contact

USE [yentel]
/****** Object:  Table [dbo].[Contact]    Script Date: 08/10/2011 18:52:03 ******/
CREATE TABLE [dbo].[Contact](
      [City] [varchar](100) NULL,
      [Address] [varchar](100) NULL,
      [Name] [varchar](100) NULL,
      [IDContact] [varchar](38) NOT NULLON [PRIMARY]
ALTER TABLE [dbo].[Contact] ADD  CONSTRAINT [UK_ContactIDContact]  
DEFAULT (newid()) FOR [IDContact]

The last instruction will automatically create a new IDContact for you for new contacts.


Insert some data in this table

Pressing the exclamation symbol will refresh the table and the new ID's will be shown..


Adding data to your table can also be done using Access.

Open Access

From the File menu, select new.

On the right side, select "Project using existing data"

Give it a name

And click the create button.

In the next window, insert the database URL and your credentials.

And click OK.

Click Save Password is the easiest way.

Another way for creating the table is using TSQL in a bat file.

Open Notepad.

Insert the code below

Code for TSQL batch file

Print 'START(A)'
GO 1
        SELECT *
        WHERE TABLE_NAME = 'Contact'
CREATE TABLE [dbo].[Contact] (
      [City] [varchar] (100)  NULL ,
      [Address] [varchar] (100)  NULL ,
      [Name] [varchar] (100)  NULL ,
      [IDContact] [varchar] (38)   NOT NULL
      ) ON [PRIMARY]
            ALTER TABLE [dbo].[Contact] WITH NOCHECK ADD
                  CONSTRAINT [PK_Contact] PRIMARY KEY  CLUSTERED
                  )  ON [PRIMARY]
            ALTER TABLE [dbo].[Contact] ADD
                  CONSTRAINT [UK_ContactIDContact] DEFAULT (newid()) FOR 
            CREATE  INDEX [IX_Contact] ON [dbo].[Contact]([IDContact]) ON 
            SET ANSI_NULLS ON

Save this file on disk as "O_Contact.txt".

Create a new text file containing the code below

Code for TSQL batch file

OSQL.EXE  -U UserName -P Password -S sql1.vaisulweb.it 
-i C:\Frans\O_Contact.txt -o C:\Frans\O_Contact.out -d Yentel

And save it to disk as contact.bat.

It contains


Now when you double click the bat file, your txt file will be executed. The "O_Contact.out" will contain the result. You can open it in Notepad.

You can use this structure for all kinds of database commands; create tables, create or delete stored procedures etc.


Now that the table is created, we need a stored procedure to get the information from the contact table in our project.

Stored procedures

Create the Contact stored procedure

            Contact.IDContact AS IDContact,
            Contact.City AS City,
            Contact.Address AS Address,
            Contact.Name AS Name
FROM Contact

(You can insert this text into the O_Contact.txt file and click the same bat file)

This was the preparation. Now we need to add our datagrid and our Servicereference.


View Entire Article

User Comments

Title: C# Code example   
Name: eilering
Date: 2011-09-16 3:50:25 AM
The VB code is very basic. If you copy the code and use a convertor like
then you can paste it and you get the C# code.

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-22 3:44:12 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search