0

I want to make a query like this.

SELECT @rownum:=@rownum+1 'rank' FROM (SELECT @rownum:=0) r

When I test it on my mysql query browser, it works well.

Now, I want to execute it in VB with mysqlCommand. of course @rownum is defined as a parameter and waiting for its value. How can I execute that query in VB?

3 Answers 3

1

You will need to add the variable to the command's parameters:

command.Parameters.AddWithValue("@rownum", rownum)

Some documentation is here: http://dev.mysql.com/doc/refman/5.0/es/connector-net-examples-mysqlparametercollection.html

Sign up to request clarification or add additional context in comments.

1 Comment

did you mean that I replace @ rownum from my command text with @ rownum again? I've tried, but it give me an error on my syntax.. :(
1

You must add this key to your connection string: 'Allow User Variables=True;'

1 Comment

Thank you! Been trying to figure this out for hours!
0
dim conn As New MySqlConnection <br>
dim comm As New MySqlCommand<br><br>
dim dAdapter As New MySqlDataAdapter<br>
dim ddata As New DataSet<br>

conn.ConnectionString = "DATABASE=" & ddatabase & ";SERVER=" & Trim(TextBox1.Text) & ";user id=dev;password=revolution;port=" & TextBox3.Text & " ;charset=utf8;<b>Allow User Variables=True" </b><br>
conn.Open() <br>
<br>
comm.Connection = conn<br>
comm.CommandText = "set @rownum = 10"<br>
comm.ExecuteNonQuery() <br>
<br>
ddata.Clear()<br>
ddata.Tables.Clear()<br>
comm.Connection = conn<br>
comm.CommandText = "select @rownum rownum"<br>
dAdapter.SelectCommand = comm <br>
dAdapter.Fill(ddata)<br>
<br>
msgbox(ddata.Tables(0).Rows(0).Item("rownum")) <br>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.