Link to home
Start Free TrialLog in
Avatar of kwickway
kwickway

asked on

ADO.NET Simple Usages....

Hello, i am inquring about ADO.NET and want to know the following using code only...

I want to open the database using a connection string of any kind

Then i want to open a specfic table in a database

Then i want to be able to have the following:
  2 text boxs, and a button, basicly when the user enters a first name in the first textbox and presses the button, it will then open the database and search for the record, then once the record has been found (the first occurance) then it will display the last name in textbox2 (in vb.6 i use to use rs.fields("l_name") etc...)

Then once it does this, i want the user to be able to change the last name and have the user hit a second button to update the field

then i want the table updated and saved (database)

then i want the database closed..

I would also like to know how to do simple quaries like insert, delete tables, etc....
ASKER CERTIFIED SOLUTION
Avatar of Mani Pazhana
Mani Pazhana
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kwickway
kwickway

ASKER

Mani, Can i pretty much put any DSN or ODBC connection string in there?  And how do i create a database or table in that example?
(and that is ADO.NET right)
yes you can use ODBC connection string.

Strictly follow the syntax. The connection string syntax is given below in this article:

http://www.sqlstrings.com/

http://www.sqlstrings.com/SQL-Server-connection-strings.htm

http://www.able-consulting.com/ADO_Conn.htm

you can use according to your scenario.


Hope it helps

Thanks

Regarding your question:
And how do i create a database or table in that example?

1) you can create database and tables at the backend.(recommended)
CREATE DATABASE
Creates a new database and the files used to store the database, or attaches a database from the files of a previously created database.



Note  For more information about backward compatibility with DISK INIT, see Devices (Level 3) in Microsoft® SQL Server™ Backward Compatibility Details.


Syntax
CREATE DATABASE database_name
[ ON
    [ < filespec > [ ,...n ] ]
    [ , < filegroup > [ ,...n ] ]
]
[ LOG ON { < filespec > [ ,...n ] } ]
[ COLLATE collation_name ]
[ FOR LOAD | FOR ATTACH ]

< filespec > ::=

[ PRIMARY ]
( [ NAME = logical_file_name , ]
    FILENAME = 'os_file_name'
    [ , SIZE = size ]
    [ , MAXSIZE = { max_size | UNLIMITED } ]
    [ , FILEGROWTH = growth_increment ] ) [ ,...n ]

< filegroup > ::=

FILEGROUP filegroup_name < filespec > [ ,...n ]

----------------------------------------------------------------------------

CREATE TABLE
Creates a new table.

Syntax
CREATE TABLE
    [ database_name.[ owner ] . | owner. ] table_name
    ( { < column_definition > 
        | column_name AS computed_column_expression
        | < table_constraint > ::= [ CONSTRAINT constraint_name ] }

            | [ { PRIMARY KEY | UNIQUE } [ ,...n ]
    )

[ ON { filegroup | DEFAULT } ]
[ TEXTIMAGE_ON { filegroup | DEFAULT } ]

< column_definition > ::= { column_name data_type }
    [ COLLATE < collation_name > ]
    [ [ DEFAULT constant_expression ]
        | [ IDENTITY [ ( seed , increment ) [ NOT FOR REPLICATION ] ] ]
    ]
    [ ROWGUIDCOL]
    [ < column_constraint > ] [ ...n ]

< column_constraint > ::= [ CONSTRAINT constraint_name ]
    { [ NULL | NOT NULL ]
        | [ { PRIMARY KEY | UNIQUE }
            [ CLUSTERED | NONCLUSTERED ]
            [ WITH FILLFACTOR = fillfactor ]
            [ON {filegroup | DEFAULT} ] ]
        ]
        | [ [ FOREIGN KEY ]
            REFERENCES ref_table [ ( ref_column ) ]
            [ ON DELETE { CASCADE | NO ACTION } ]
            [ ON UPDATE { CASCADE | NO ACTION } ]
            [ NOT FOR REPLICATION ]
        ]
        | CHECK [ NOT FOR REPLICATION ]
        ( logical_expression )
    }

< table_constraint > ::= [ CONSTRAINT constraint_name ]
    { [ { PRIMARY KEY | UNIQUE }
        [ CLUSTERED | NONCLUSTERED ]
        { ( column [ ASC | DESC ] [ ,...n ] ) }
        [ WITH FILLFACTOR = fillfactor ]
        [ ON { filegroup | DEFAULT } ]
    ]
    | FOREIGN KEY
        [ ( column [ ,...n ] ) ]
        REFERENCES ref_table [ ( ref_column [ ,...n ] ) ]
        [ ON DELETE { CASCADE | NO ACTION } ]
        [ ON UPDATE { CASCADE | NO ACTION } ]
        [ NOT FOR REPLICATION ]
    | CHECK [ NOT FOR REPLICATION ]
        ( search_conditions )
    }

-------------------------------------------------------------------------------



2)you can create databases and table using SQL enterprise manager(more easy to create).

refer SQL Books online documentation.

Good luck
I first have to tell you this.... ...I am impressed with this...  Thanks...

When you say backend your not talking about during the runtime are you?  Can i execute a "create database" command in run time?  I just want to make a personal knolage base for myself.
you can execute SQL statements using the code below:

Instead of update statement you can use any valid SQL statement like create database, create table etc....

Hope it helps.

 'build sql connection string at run time
        Dim connect As New SqlConnection("Initial Catalog = Northwind;Data Source=(local); User ID=sa; password =test;")

        'Opns the SQL Connection
        connect.Open()

        'open command object(takes two parameters sqlstring, connection)
        Dim command As New SqlCommand("Update Employees Set LastName = '" & TextBox2.Text & "'," _
                         & " HomePhone = '" & TextBox3.Text & "' where FirstName = '" & TextBox1.Text & "'", connect)

        'execute command object
        command.ExecuteNonQuery()


        'clean up code
        command.Dispose()
        connect.Close()
        connect = Nothing

Hello again....

I posted the file attachment at http://www.vbcity.com/forums/attachment.asp?id=9947 (nearly compleated...

I want to know how using this source code to take the BLOB data out of the northwind database (again using my example) showing the picture in the Nortwind.Employee Database for each employee onto a picturebox
Both of us are still trying to figure out this code, but Mani, if you can figure that out too, let us know.... :)  Im sure its easy...
i have not come across your situation.

please try to post one more time with your latest question, some one will definitely help you out.

Thanks