none
Argument 'Prompt' cannot be converted to type 'String'. RRS feed

  • Question

  • I am having exception while running code. Connection string is saved into app.config ple. please help

    ----------------------------------------------CLASS______________________________

    Imports System.Data.SqlClient
    Imports System.Configuration
    Public Class Form1
        Private Sub UserAddBtn_Click(sender As Object, e As EventArgs) Handles UserAddBtn.Click
            Try
                Dim CS = ConfigurationManager.ConnectionStrings("DBConnectionString").ConnectionString
                'Dim cn As New SqlConnection("Data Source=DELL-3000\SQLEXPRESS;Initial Catalog=TestConnectionString;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False")
                Dim Cn As New SqlConnection(CS)
                Dim cmd As New SqlCommand
                cmd.Connection = Cn
                If UUserNameTxt.Text <> "" Then
                    'And CPurchaseCombo.Text <> "" And CEmpUsingTxt.Text <> "" And CHDDTxt.Text <> "" And CSSDTxt.Text <> "" And CRAMTxt.Text <> "" And CProcessorTxt.Text <> "" And CVGATxt.Text <> "" And COthersTxt.Text <> "" Then
                    Cn.Open()
                    cmd.CommandText = "insert into Users(ID,Fname,Lname,Username,Password) values ('" & UIDTxt.Text & "', '" & UFnameTxt.Text & "', '" & ULnameTxt.Text & "', '" & UUserNameTxt.Text & "', '" & UPasswordTxt.Text & "')"
                    cmd.ExecuteNonQuery()
                    Cn.Close()
                    MsgBox("Inserted Succefully")
                ElseIf UUserNameTxt.Text = "" Then
                    ' Else
                    MsgBox("Please Atleast provide the computer name")
                End If
            Catch ex As Exception
                MsgBox(ex)
            End Try
        End Sub

    End Class

    __________________________________APP.Config________________________________

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <startup>
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
        </startup>
      <connectionstrings>
        <add name="DBConnectionString"   providerName="System.Data.SqlClient"
          ConnectionString="Data Source=DELL\SQLEXPRESS;Initial Catalog=TestConnectionString;Integrated Security=True;"/>
      </connectionstrings>
     
     
     
    </configuration>


    jawad ali

    Friday, August 11, 2017 10:56 PM

All replies


  • Regards Les, Livingston, Scotland

    Friday, August 11, 2017 11:01 PM
  • I am having exception while running code.

    You haven't indicated what line of code creates the error.  If it is this line:

                MsgBox(ex)

    then change it to

                MsgBox(ex.ToString)

    If this is a WPF application then post your question at Windows Presentation  Foundation (WPF) 


    • Proposed as answer by Frank L. Smith Saturday, August 12, 2017 12:30 AM
    Saturday, August 12, 2017 12:00 AM

  • If this is a WPF application then post your question at Windows Presentation  Foundation (WPF) 


    @Acamar,

    No defitaly not those don't start with a class name like Form1 but with Window. The XAML you think to see is the config.Sys


    Success
    Cor


    Saturday, August 12, 2017 10:20 AM
  • If you have an expression error than show it. If it is not in English than use Google translate. 

    However, there is a lot wrong in your code. 

    But let us start with your config.sys

    you can try this one. 

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
      </configSections>
      <connectionStrings>
        <add name="yourprojectname.My.MySettings.DBConnectionString" connectionString="providerName=System.Data.SqlClient Data Source=DELL\SQLEXPRESS;Initial Catalog=TestConnectionString;Integrated Security=True" />
      </connectionStrings>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
      </startup>
    </configuration>
    Be aware your code is very old fashioned and has many changes to fail. 


    Success
    Cor




    Saturday, August 12, 2017 10:44 AM
  • Hi JimmyJawad,

    Since you didn't provide where to encounter this error message, you can try Acamar's suggestion first, then modify sql query line. Because your ID field is integer, but you insert string value  UIDTxt.Text , modify:

    Convert.ToInt32(UIDTxt.Text )

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, August 14, 2017 1:53 AM
    Moderator
  • Hi JimmyJawad,

    Since you didn't provide where to encounter this error message, you can try Acamar's suggestion first, then modify sql query line. Because your ID field is integer, but you insert string value  UIDTxt.Text , modify:

    Convert.ToInt32(UIDTxt.Text )


    Cherry

    Why? I hope the OP is a MSDN subscriber, because your reply is really offending after what I wrote. 



    Success
    Cor

    Monday, August 14, 2017 8:07 AM