M
Morten Snedker
On a web-form the user enters basic data (company name, phone,
areacode etc).
Many we have already registrered and some not. For those we have we
wish to make the enter of data easier by looking them up.
This looks up 1 value:
Sub LookUpVVS()
Dim sqlCon As New SqlConnection
sqlCon.ConnectionString = conString
Try
sSQL = "SELECT Firmanavn FROM tblVVS WHERE
Telefon=@TelefonNr"
sqlCon.Open()
Dim cmd As New SqlCommand(sSQL, sqlCon)
Dim p1 As New SqlParameter("@TelefonNr",
Data.SqlDbType.Int)
p1.Value = Me.txtTelefon.Text
cmd.Parameters.Add(p1)
Me.txtFirma.Text = cmd.ExecuteScalar().ToString
sqlCon.Close()
sqlCon.Dispose()
Catch ex As Exception
Response.Write(ex.Message)
Exit Sub
End Try
End Sub
In total I have 10 fields I wish to look up and put into the webform.
Is Executescalar the wrong approach? I ask cause I don't know if
there's a simpler way to use Excecutescalar.
I'm thinking that I should use a dataset instaed that holds the entire
record.
Regards /Snedker
areacode etc).
Many we have already registrered and some not. For those we have we
wish to make the enter of data easier by looking them up.
This looks up 1 value:
Sub LookUpVVS()
Dim sqlCon As New SqlConnection
sqlCon.ConnectionString = conString
Try
sSQL = "SELECT Firmanavn FROM tblVVS WHERE
Telefon=@TelefonNr"
sqlCon.Open()
Dim cmd As New SqlCommand(sSQL, sqlCon)
Dim p1 As New SqlParameter("@TelefonNr",
Data.SqlDbType.Int)
p1.Value = Me.txtTelefon.Text
cmd.Parameters.Add(p1)
Me.txtFirma.Text = cmd.ExecuteScalar().ToString
sqlCon.Close()
sqlCon.Dispose()
Catch ex As Exception
Response.Write(ex.Message)
Exit Sub
End Try
End Sub
In total I have 10 fields I wish to look up and put into the webform.
Is Executescalar the wrong approach? I ask cause I don't know if
there's a simpler way to use Excecutescalar.
I'm thinking that I should use a dataset instaed that holds the entire
record.
Regards /Snedker