Reputation: 376
for a few days I've been trying and trying to get the stored procedure to work in vb.net, but I can't seem to make it work.
I'd really appreciate it if someone could help me out here. I've been trying really hard to solve this problem, but I just can't find a solution.
Private Sub getID()
Dim ds As New DataSet
Dim con_str = ""
Dim con As MySql.Data.MySqlClient.MySqlConnection = New MySql.Data.MySqlClient.MySqlConnection(con_str)
con.Open()
Dim cmd As MySql.Data.MySqlClient.MySqlCommand = New MySql.Data.MySqlClient.MySqlCommand
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "getID()"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@id", "113")
Dim da As MySql.Data.MySqlClient.MySqlDataAdapter = New MySql.Data.MySqlClient.MySqlDataAdapter(cmd)
Dim dt As New DataTable
da.SelectCommand.Connection = con
da.Fill(dt)
End Sub
When I try to run this I get the exception "Incorrect number of arguments for PROCEDURE otrs.getID; expected 1, got 0" on the line da.Fill(dt). I don't really know why this happens. There is no argument declared in my stored procedure.
My stored procedure should be fine. Calling it out of the dbms worked out fine, but here is the code anyways:
delimiter $$
CREATE DEFINER=`otrs`@`%` PROCEDURE `getCIs`()
BEGIN
SELECT
l.source_key AS base_id,
c1.configitem_number AS base_number,
v.name as base_name,
l.target_key AS link_id,
c2.configitem_number AS link_number,
v1.name as link_name,
t.name as link_type
FROM
otrs.link_relation AS l
INNER JOIN
otrs.configitem AS c1
ON l.source_key = c1.id
INNER JOIN
otrs.configitem AS c2
ON l.target_key = c2.id
INNER JOIN
otrs.link_type AS t
INNER JOIN
otrs.configitem_version AS v
ON l.source_key = v.configitem_id
INNER JOIN
otrs.configitem_version AS v1
ON l.target_key = v1.configitem_id;
END$$
And yes, I did use the search-function and I googled quite a lot, but I'm still thankful for any kind of information regarding my problem.
So I found out was wrong. Apparently you dont need the () after the procedure-name. Im not 100% sure though, because now nothing happens at all:
Private Sub getID()
Dim ds As New DataSet
Dim con_str = ""
Dim con As MySql.Data.MySqlClient.MySqlConnection = New MySql.Data.MySqlClient.MySqlConnection(con_str)
con.Open()
Dim cmd As MySql.Data.MySqlClient.MySqlCommand = New MySql.Data.MySqlClient.MySqlCommand
cmd.CommandType = CommandType.StoredProcedure
Try
cmd.CommandText = "getID"
Catch ex As Exception
MsgBox(ex.Message())
End Try
cmd.Parameters.AddWithValue("@id", 113)
cmd.Connection = con
Dim da As MySql.Data.MySqlClient.MySqlDataAdapter = New MySql.Data.MySqlClient.MySqlDataAdapter(cmd)
Dim dt As New DataTable
Try
da.Fill(dt)
Catch ex As Exception
MsgBox(ex.Message())
End Try
End Sub
Upvotes: 1
Views: 3133
Reputation: 59
You never actually execute cmd. Also, as you mentioned above, you don't need the parenthesis for the proc call. It should look something like this.
MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter("getID", con);
DataSet DS = new DataSet();
mySqlDataAdapter.Fill(DS);
Upvotes: 1
Reputation: 52645
This line is wrong it creates a new command with the command text of "call getID()" and adds it to the adapter with no parameters
Dim da As MySql.Data.MySqlClient.MySqlDataAdapter = _
New MySql.Data.MySqlClient.MySqlDataAdapter("call getID()", con_str)
you want
cmd.CommandText = "getID"
Dim da As MySql.Data.MySqlClient.MySqlDataAdapter = _
New MySql.Data.MySqlClient.MySqlDataAdapter(cmd, con_str)
Upvotes: 0