i have this connection string 

<connectionStrings>
    <add name="Tendering_Pro" connectionString="Data Source=HABOUSH-PC\SQLEXPRESS;Initial Catalog=TenderingProgram;Integrated Security=True"
        providerName="System.Data.SqlClient" />
  </connectionStrings>

    <system.diagnostics>




    AND THIS MY CLAAS : 
    Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration


Public Class BuyNewTender


    Private conn As SqlConnection
    Private _MSG As String = ""

    Private _ProjectTenderingNO As String = ""
    Private _TenderingNo As String = ""
    Private _ProjectName As String = ""
    Private _Clientname As String = ""
    Private _PurchasePrice As Integer = 0
    Private _BuyDate As String = ""
    Private _TenderClosingDate As String = ""
    Private _DocumentDetail As String = ""
    Private _Notes As String = ""


    Public Property ProjectTenderingNO() As String
        Get
            Return _ProjectTenderingNO
        End Get
        Set(ByVal value As String)
            _ProjectTenderingNO = value
        End Set
    End Property

    Public Property ProjectName() As String
        Get
            Return _ProjectName
        End Get
        Set(ByVal value As String)
            _ProjectName = value
        End Set
    End Property

    Public Property TenderingNO() As String
        Get
            Return _TenderingNo
        End Get
        Set(ByVal value As String)
            _TenderingNo = value
        End Set
    End Property

    Public Property Clientname() As String
        Get
            Return _Clientname
        End Get
        Set(ByVal value As String)
            _Clientname = value
        End Set
    End Property

    Public Property PurchasePrice() As Integer
        Get
            Return _PurchasePrice
        End Get
        Set(ByVal value As Integer)
            _PurchasePrice = value
        End Set
    End Property

    Public Property BuyDate() As String
        Get
            Return _BuyDate
        End Get
        Set(ByVal value As String)
            _BuyDate = value
        End Set
    End Property

    Public Property TenderClosingDate() As String
        Get
            Return _TenderClosingDate
        End Get
        Set(ByVal value As String)
            _TenderClosingDate = value
        End Set
    End Property

    Public Property DocumentDetail() As String
        Get
            Return _DocumentDetail
        End Get
        Set(ByVal value As String)
            _DocumentDetail = value
        End Set
    End Property

    Public Property Notes() As String
        Get
            Return _Notes
        End Get
        Set(ByVal value As String)
            _Notes = value
        End Set
    End Property

    Public ReadOnly Property GetMSG() As String
        Get
            Return _MSG
        End Get
    End Property

    Private Sub GetConnection()

        Dim DbConnection As String = System.Configuration.ConfigurationManager.ConnectionStrings("Tendering_Pro").ConnectionString
        Try
            Me.conn = New SqlConnection(DbConnection)
            Me.conn.Open()
        Catch ex As Exception

            Me._MSG = ex.Message

        End Try
    End Sub
    Public Sub add()

        GetConnection()
        Dim sql As String = "INSERT INTO [BuyNewTender] "
        sql = sql & "([ProjectTenderingNO]"
        sql = sql & "  ,[TenderingNo]"
        sql = sql & "  ,[ProjectName]"
        sql = sql & "  ,[Clientname]"
        sql = sql & "   ,[PurchasePrice]"
        sql = sql & "  ,[BuyDate]"
        sql = sql & "  ,[TenderClosingDate]"
        sql = sql & "   ,[DocumentDetail]"
        sql = sql & "  ,[Notes])"
        sql = sql & " VALUES()"
        sql = sql & "   (@ProjectTenderingNO"
        sql = sql & "   ,@TenderingNo"
        sql = sql & "   ,@ProjectName"
        sql = sql & "   ,@Clientname"
        sql = sql & "   ,@PurchasePrice"
        sql = sql & "   ,@BuyDate"
        sql = sql & "   ,@TenderClosingDate"
        sql = sql & "   ,@DocumentDetail]"
        sql = sql & "   ,@Notes)"

        Dim cmd As New SqlCommand(sql, conn)

        cmd.Parameters.Add("@ProjectTenderingNO", SqlDbType.NVarChar).Value = _ProjectTenderingNO
        cmd.Parameters.Add("@TenderingNo", SqlDbType.NVarChar).Value = _TenderingNo
        cmd.Parameters.Add("@ProjectName", SqlDbType.NVarChar).Value = _ProjectName
        cmd.Parameters.Add("@Clientname", SqlDbType.NVarChar).Value = _Clientname
        cmd.Parameters.Add("@PurchasePrice", SqlDbType.Int).Value = _PurchasePrice
        cmd.Parameters.Add("@BuyDate", SqlDbType.Date).Value = _BuyDate
        cmd.Parameters.Add("@TenderClosingDate", SqlDbType.Date).Value = _TenderClosingDate
        cmd.Parameters.Add("@DocumentDetail", SqlDbType.NVarChar).Value = _DocumentDetail
        cmd.Parameters.Add("@Notes", SqlDbType.NVarChar).Value = _Notes

        Try
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            Me._MSG = ex.Message
        Finally
            If conn.State = ConnectionState.Open Then
                conn.Close()
            End If
        End Try

    End Sub


    END CLASS 
    AND THIS IS INSIDE ADD BUTTON 
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click




        Dim objBuyNewTender As New BuyNewTender

        If (txtProjectTNO.Text Is Nothing) Then
            objBuyNewTender.ProjectTenderingNO = ""
        Else
            objBuyNewTender.ProjectTenderingNO = txtProjectTNO.Text
        End If


        If (txtTenderNO.Text Is Nothing) Then
            objBuyNewTender.TenderingNO = ""
        Else

            objBuyNewTender.TenderingNO = txtTenderNO.Text.ToString
        End If


        If (txtProjectName.Text Is Nothing) Then
            objBuyNewTender.ProjectName = ""
        Else

            objBuyNewTender.ProjectName = txtProjectName.Text
        End If

        If (txtClientName.Text Is Nothing) Then
            objBuyNewTender.Clientname = ""
        Else

            objBuyNewTender.Clientname = txtClientName.Text
        End If

        If (txtPurchasePrice.Text Is Nothing) Then
            objBuyNewTender.PurchasePrice = 0
        Else

            objBuyNewTender.PurchasePrice = txtPurchasePrice.Text
        End If


        If (DTPBuyDate.Text Is Nothing) Then
            objBuyNewTender.BuyDate = ""
        Else

            objBuyNewTender.BuyDate = DTPBuyDate.Text
        End If

        If (DTPTenderingClosing.Text Is Nothing) Then
            objBuyNewTender.TenderClosingDate = ""
        Else

            objBuyNewTender.TenderClosingDate = DTPTenderingClosing.Text
        End If

        If (txtDocumentDetail.Text Is Nothing) Then
            objBuyNewTender.DocumentDetail = ""
        Else

            objBuyNewTender.DocumentDetail = txtDocumentDetail.Text
        End If


        If (txtNotes.Text Is Nothing) Then
            objBuyNewTender.Notes = ""
        Else

            objBuyNewTender.Notes = txtNotes.Text
        End If


        objBuyNewTender.add()
        MessageBox.Show("Project Defintion Saved Successfully")

BUT THERE IS NO ERROR AND THERE IS NO DATA SAVED TO SQL SERVER , CAN SOME ONE TELL ME WHY ?? 

Recommended Answers

All 3 Replies

Your INSERT statement looks like:

Dim sql As String = "INSERT INTO [BuyNewTender] ([ProjectTenderingNO] ,[TenderingNo] ,[ProjectName] ,[Clientname] ,[PurchasePrice] ,[BuyDate] ,[TenderClosingDate] ,[DocumentDetail] ,[Notes]) VALUES() (@ProjectTenderingNO,@TenderingNo ,@ProjectName ,@Clientname ,@PurchasePrice  ,@BuyDate ,@TenderClosingDate  ,@DocumentDetail] ,@Notes)"

SQL executes this sentence by evaluating first

INSERT INTO [BuyNewTender] ([ProjectTenderingNO] ,[TenderingNo] ,[ProjectName] ,[Clientname] ,[PurchasePrice] ,[BuyDate] ,[TenderClosingDate] ,[DocumentDetail] ,[Notes]) VALUES()

wich results in an empty set of values, then evaluates the

(@ProjectTenderingNO,@TenderingNo ,@ProjectName ,@Clientname ,@PurchasePrice  ,@BuyDate ,@TenderClosingDate  ,@DocumentDetail] ,@Notes)

wich results in an evaluation of values in the memory of SQL server not needed any more and discarded.

There is no Exception because the sintax is mostly 'valid'.

I'll suggest to remove the () in the line 148. Also the ] in line 156.

Hope this helps

commented: Good to see you back.. We missed you. +11

ty lolafuertes thats very helpful.

Tx.
Please, if this solved your issue, mark this thread as solved.
Tx in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.