How to compare a string to a datarow

Asked

Viewed 24 times

0

that’s the code:

Dim clientesCadastrados As DataTable = MnipulaDB.ConsultaSql("SELECT CAMPO1 AS NOME FROM TAB_CLIENTES WHERE CAMPO21 =1")
For Each cliente As DataRow In clientesCadastrados.Rows
 If campo3.texto <> cliente.ToString Then
     MessageBox("Cliente não cadastrado!")
     Return
 End If
Next

A returned error says that a Datarow cannot be transformed into a String. How can I make this campo3.texto with cliente.ToString?

  • You need to compare but, brings a list of items from a correct Datatable, your SQL is not wrong?

  • That, I need to compare the text box string campo3 with the resulting names in the Datatable clientesCadastrados. I just debugged here and sql is working. The problem is that it is not possible to compare a string with a datarow.

  • tried to cliente["NOME"]?, ie, specify the field! your SQL could be a count(*) as c what you think?

  • tried, this syntax does not work with Vb.net :/

  • because that’s how it is cliente("NOME"), I confused with C#

  • opa, it worked! thanks a lot @novic

Show 1 more comment

1 answer

0


You have to specify which column the clients are in... This code below will work if your customers are in the first column (index 0)

Dim clientesCadastrados As DataTable = MnipulaDB.ConsultaSql("SELECT CAMPO1 AS NOME FROM TAB_CLIENTES WHERE CAMPO21 =1")
For Each linha As DataGridViewRow In clientesCadastrados.Rows
 If campo3.texto <> linha.Cells(0).Value.ToString Then
     MessageBox("Cliente não cadastrado!")
     Return
 End If
Next

Browser other questions tagged

You are not signed in. Login or sign up in order to post.