Web form - sql and receiving data - there is a simpler soluton

Sorry if this question is stupid, but I have no other way to see the big picture. I have 1 text box, 1 shortcut and a database with two columns (code name and description) by entering the code name in the text box. I would like to receive the corresponding description in the label.

With Excel and VBA, this can be done with a few lines. Unfortunately, I cannot use Excel, but I need to choose a web interface for slow PCs and Office pricing. Why is this simple task so complicated in ASP.NET with all the common declarations and sqlservers and sqlconnections.

Is there an easier way to do this?

BTW. I tried to adapt a lot of different things that I found on the Internet, and this last one looks promising, but it does not work:

Protected Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
    Using sqlconn As New SqlConnection("Data Source=.\sqlexpress;Initial Catalog=KLIJENTI;Integrated Security=True"), _
          sqlcmd As New SqlCommand("Select From Baza Where SIFRE = @SIFRE", sqlconn)

        sqlcmd.Parameters.Add("@SIFRE", SqlDbType.VarChar, 50).Value = TextBox2.Text

         sqlconn.Open()


        'Label1.Text = CString(sqlcmd.ExecuteScalar()) 'CString is not declared
        Label1.Text = sqlcmd.ExecuteScalar()


    End Using
End Sub

Baza - ,

SIFRE - ,

NAZIV - , SIFRE, Label

+4
1

Protected Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
    Using sqlconn = New SqlConnection("Data Source=.\sqlexpress;Initial Catalog=KLIJENTI;Integrated Security=True")
    Using sqlcmd = New SqlCommand("Select NAZIV From Baza Where SIFRE = @SIFRE", sqlconn)
        sqlcmd.Parameters.AddWithValue("@SIFRE", TextBox2.Text)
        sqlconn.Open()
        Dim result = sqlcmd.ExecuteScalar()
        if result IsNot Nothing Then
           Label1.Text = result.ToString
        End If
    End Using
    End Using
End Sub

SELECT sql , . ( NAZIV)
, @Sifre, ExecuteScalar Nothing.

+4

Source: https://habr.com/ru/post/1531432/


All Articles