Unable to convert System.Date and System.int to System.String, error












0














I'm trying to search a keyword in the SQL Server db from Textbox1 and printing the corresponding details in other TextBoxes.



While running the below code, it shows it is unable to convert the DateTime and Integer value into String to display it in the TextBoxes.



Also there is another end of statement expected error in the command.Parameter line:



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim connection As New SqlConnection("Server= DESKTOP-STMQUHM; Database = HospitalDB;Trusted_Connection=True")
Dim command As New SqlCommand("select * from Medicines where MedicineName ='" & TextBox1.Text & "' ", connection)
command.Parameters.Add("@Textbox1",SqlDbType.Text)Value=TextBox1.Text 'Another error
Dim adapter As New SqlDataAdapter(command)
Dim table As New DataTable()
adapter.Fill(table)
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""

If table.Rows.Count() > 0 Then
TextBox1.Text = table.Rows(0)(1).ToString
TextBox2.Text = table.Rows(0)(2).ToString
TextBox3.Text = table.Rows(0)(3).ToString
TextBox4.Text = table.Rows(0)(4).ToString
Else
MessageBox.Show("NO DATA FOUND!!")
End If
End Sub









share|improve this question
























  • You're missing a dot at: command.Parameters.Add("@Textbox1",SqlDbType.Text)Value=TextBox1.Text it should be: command.Parameters.Add("@Textbox1",SqlDbType.Text).Value=TextBox1.Text, though you haven't added a parameter named Textbox1 to your query. Change it to: select * from Medicines where MedicineName = @Textbox1 (no string concatenation).
    – Visual Vincent
    Nov 12 at 17:45


















0














I'm trying to search a keyword in the SQL Server db from Textbox1 and printing the corresponding details in other TextBoxes.



While running the below code, it shows it is unable to convert the DateTime and Integer value into String to display it in the TextBoxes.



Also there is another end of statement expected error in the command.Parameter line:



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim connection As New SqlConnection("Server= DESKTOP-STMQUHM; Database = HospitalDB;Trusted_Connection=True")
Dim command As New SqlCommand("select * from Medicines where MedicineName ='" & TextBox1.Text & "' ", connection)
command.Parameters.Add("@Textbox1",SqlDbType.Text)Value=TextBox1.Text 'Another error
Dim adapter As New SqlDataAdapter(command)
Dim table As New DataTable()
adapter.Fill(table)
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""

If table.Rows.Count() > 0 Then
TextBox1.Text = table.Rows(0)(1).ToString
TextBox2.Text = table.Rows(0)(2).ToString
TextBox3.Text = table.Rows(0)(3).ToString
TextBox4.Text = table.Rows(0)(4).ToString
Else
MessageBox.Show("NO DATA FOUND!!")
End If
End Sub









share|improve this question
























  • You're missing a dot at: command.Parameters.Add("@Textbox1",SqlDbType.Text)Value=TextBox1.Text it should be: command.Parameters.Add("@Textbox1",SqlDbType.Text).Value=TextBox1.Text, though you haven't added a parameter named Textbox1 to your query. Change it to: select * from Medicines where MedicineName = @Textbox1 (no string concatenation).
    – Visual Vincent
    Nov 12 at 17:45
















0












0








0







I'm trying to search a keyword in the SQL Server db from Textbox1 and printing the corresponding details in other TextBoxes.



While running the below code, it shows it is unable to convert the DateTime and Integer value into String to display it in the TextBoxes.



Also there is another end of statement expected error in the command.Parameter line:



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim connection As New SqlConnection("Server= DESKTOP-STMQUHM; Database = HospitalDB;Trusted_Connection=True")
Dim command As New SqlCommand("select * from Medicines where MedicineName ='" & TextBox1.Text & "' ", connection)
command.Parameters.Add("@Textbox1",SqlDbType.Text)Value=TextBox1.Text 'Another error
Dim adapter As New SqlDataAdapter(command)
Dim table As New DataTable()
adapter.Fill(table)
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""

If table.Rows.Count() > 0 Then
TextBox1.Text = table.Rows(0)(1).ToString
TextBox2.Text = table.Rows(0)(2).ToString
TextBox3.Text = table.Rows(0)(3).ToString
TextBox4.Text = table.Rows(0)(4).ToString
Else
MessageBox.Show("NO DATA FOUND!!")
End If
End Sub









share|improve this question















I'm trying to search a keyword in the SQL Server db from Textbox1 and printing the corresponding details in other TextBoxes.



While running the below code, it shows it is unable to convert the DateTime and Integer value into String to display it in the TextBoxes.



Also there is another end of statement expected error in the command.Parameter line:



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim connection As New SqlConnection("Server= DESKTOP-STMQUHM; Database = HospitalDB;Trusted_Connection=True")
Dim command As New SqlCommand("select * from Medicines where MedicineName ='" & TextBox1.Text & "' ", connection)
command.Parameters.Add("@Textbox1",SqlDbType.Text)Value=TextBox1.Text 'Another error
Dim adapter As New SqlDataAdapter(command)
Dim table As New DataTable()
adapter.Fill(table)
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""

If table.Rows.Count() > 0 Then
TextBox1.Text = table.Rows(0)(1).ToString
TextBox2.Text = table.Rows(0)(2).ToString
TextBox3.Text = table.Rows(0)(3).ToString
TextBox4.Text = table.Rows(0)(4).ToString
Else
MessageBox.Show("NO DATA FOUND!!")
End If
End Sub






sql-server vb.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 17:51









Jimi

6,74441533




6,74441533










asked Nov 12 at 17:36









Sidharth K

53




53












  • You're missing a dot at: command.Parameters.Add("@Textbox1",SqlDbType.Text)Value=TextBox1.Text it should be: command.Parameters.Add("@Textbox1",SqlDbType.Text).Value=TextBox1.Text, though you haven't added a parameter named Textbox1 to your query. Change it to: select * from Medicines where MedicineName = @Textbox1 (no string concatenation).
    – Visual Vincent
    Nov 12 at 17:45




















  • You're missing a dot at: command.Parameters.Add("@Textbox1",SqlDbType.Text)Value=TextBox1.Text it should be: command.Parameters.Add("@Textbox1",SqlDbType.Text).Value=TextBox1.Text, though you haven't added a parameter named Textbox1 to your query. Change it to: select * from Medicines where MedicineName = @Textbox1 (no string concatenation).
    – Visual Vincent
    Nov 12 at 17:45


















You're missing a dot at: command.Parameters.Add("@Textbox1",SqlDbType.Text)Value=TextBox1.Text it should be: command.Parameters.Add("@Textbox1",SqlDbType.Text).Value=TextBox1.Text, though you haven't added a parameter named Textbox1 to your query. Change it to: select * from Medicines where MedicineName = @Textbox1 (no string concatenation).
– Visual Vincent
Nov 12 at 17:45






You're missing a dot at: command.Parameters.Add("@Textbox1",SqlDbType.Text)Value=TextBox1.Text it should be: command.Parameters.Add("@Textbox1",SqlDbType.Text).Value=TextBox1.Text, though you haven't added a parameter named Textbox1 to your query. Change it to: select * from Medicines where MedicineName = @Textbox1 (no string concatenation).
– Visual Vincent
Nov 12 at 17:45














1 Answer
1






active

oldest

votes


















1














Try to change this:



Dim command As New SqlCommand("select * from Medicines where MedicineName ='" &  TextBox1.Text & "' ", connection)
command.Parameters.Add("@Textbox1",SqlDbType.Text)Value=TextBox1.Text


Into this:



Dim command As New SqlCommand("select * from Medicines where MedicineName = @MedicineName", connection)
command.Parameters.Add("@MedicineName",SqlDbType.Text).Value=TextBox1.Text


This is because you have not declared the parameter name into your original SQL string, then on the second line of your code, before Value, you're missing a dot.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267341%2funable-to-convert-system-date-and-system-int-to-system-string-error%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Try to change this:



    Dim command As New SqlCommand("select * from Medicines where MedicineName ='" &  TextBox1.Text & "' ", connection)
    command.Parameters.Add("@Textbox1",SqlDbType.Text)Value=TextBox1.Text


    Into this:



    Dim command As New SqlCommand("select * from Medicines where MedicineName = @MedicineName", connection)
    command.Parameters.Add("@MedicineName",SqlDbType.Text).Value=TextBox1.Text


    This is because you have not declared the parameter name into your original SQL string, then on the second line of your code, before Value, you're missing a dot.






    share|improve this answer




























      1














      Try to change this:



      Dim command As New SqlCommand("select * from Medicines where MedicineName ='" &  TextBox1.Text & "' ", connection)
      command.Parameters.Add("@Textbox1",SqlDbType.Text)Value=TextBox1.Text


      Into this:



      Dim command As New SqlCommand("select * from Medicines where MedicineName = @MedicineName", connection)
      command.Parameters.Add("@MedicineName",SqlDbType.Text).Value=TextBox1.Text


      This is because you have not declared the parameter name into your original SQL string, then on the second line of your code, before Value, you're missing a dot.






      share|improve this answer


























        1












        1








        1






        Try to change this:



        Dim command As New SqlCommand("select * from Medicines where MedicineName ='" &  TextBox1.Text & "' ", connection)
        command.Parameters.Add("@Textbox1",SqlDbType.Text)Value=TextBox1.Text


        Into this:



        Dim command As New SqlCommand("select * from Medicines where MedicineName = @MedicineName", connection)
        command.Parameters.Add("@MedicineName",SqlDbType.Text).Value=TextBox1.Text


        This is because you have not declared the parameter name into your original SQL string, then on the second line of your code, before Value, you're missing a dot.






        share|improve this answer














        Try to change this:



        Dim command As New SqlCommand("select * from Medicines where MedicineName ='" &  TextBox1.Text & "' ", connection)
        command.Parameters.Add("@Textbox1",SqlDbType.Text)Value=TextBox1.Text


        Into this:



        Dim command As New SqlCommand("select * from Medicines where MedicineName = @MedicineName", connection)
        command.Parameters.Add("@MedicineName",SqlDbType.Text).Value=TextBox1.Text


        This is because you have not declared the parameter name into your original SQL string, then on the second line of your code, before Value, you're missing a dot.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 12 at 17:54









        Jimi

        6,74441533




        6,74441533










        answered Nov 12 at 17:44









        henoc salinas

        7151416




        7151416






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267341%2funable-to-convert-system-date-and-system-int-to-system-string-error%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            List item for chat from Array inside array React Native

            Thiostrepton

            Caerphilly