Home > Ask the Microsoft .Net Development Experts > .NET Development with XML Questions & Answers > Saving details from a form to a SQL Server table
Ask The Win Development Expert: Questions & Answers
EMAIL THIS

Saving details from a form to a SQL Server table

Daniel Cazzulino EXPERT RESPONSE FROM: Daniel Cazzulino

Pose a Question
Other Win Development Categories
Meet all Win Development Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 23 March 2004
Hi. I am trying to save details of a person from a form into the SQL server table. It's giving me the following system error: System.Data.SqlClient.SqlException.

I am using a three-tier architecture and there is a DBAS class that features the following function for executing query:

  
Public Function ConnectToDB() As SqlConnection
        Dim mCon As New SqlClient.SqlConnection(mstrConStr)
        mCon.Open()
        mintNoOfCon = mintNoOfCon + 1
        Return mCon
    End Function

Public Function ExecuteQuery(ByVal pstrSQL As String) As Boolean
        mCon = ConnectToDB()
        mCom.Connection = mCon
        mCom.CommandText = pstrSQL
      * mCom.ExecuteNonQuery()// showing problem :((
        mCon.Close()
    End Function

Can you please tell me what to do? I am a VB.NET beginner. Thanks.


>
Before executing the query, you should set the m.Com.CommandType to CommandType.Text. However, I'd strongly advise that you use the Microsoft Data Access Application Block (http://www.gotdotnet.com/Community/Workspaces/Workspace.aspx?id=c20d12b0-af52-402b-9b7c-aaeb21d1f431), which provides functionality similar to what you've done, but does so with performance in mind, and encapsulates best practices in accessing and querying database stores using ADO.NET.

It offers SQL execution using a single line of code, for example. What's more, it makes it easier to migrate to other RDBMS products by making the code agnostic to the product -- i.e., you're using SQL Server now, but a customer may want an Oracle database.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
.NET Development with XML
Modifying XML rows using XSL sheets
Generating Access data as XML for HTML publishing
Editing datagrids, take two
Creating applications to access data via mobile phones
Is it possible to schedule SQLs written for a paradox database?
Questions regarding XML for a decision making tool
Extracting data from Word 6 to populate database
How can I make a connection to a Paradox password protected database?
I have an Access Database that I want to display in a Listview.
Problem with Paradox Connection String

XML and Data
Modifying XML rows using XSL sheets
Generating Access data as XML for HTML publishing
Editing datagrids, take two
Creating applications to access data via mobile phones
Is it possible to schedule SQLs written for a paradox database?
Questions regarding XML for a decision making tool
Extracting data from Word 6 to populate database
How can I make a connection to a Paradox password protected database?
I have an Access Database that I want to display in a Listview.
Problem with Paradox Connection String

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Windows Development - White Papers, News and Expert Advice
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts