Problem solve Get help with specific problems with your technologies, process and projects.

Saving details from a form to a SQL Server table

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)
        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 :((
    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.

Dig Deeper on SQL Server and .NET development

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.