Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
mysql> create procedure login(in user varchar(20),in pass varchar(20),out date1
date)
-> begin
-> set date1 = (select Dt from emp3 where userid=user and password = pass);
-> end$$
Query OK, 0 rows affected (0.00 sec)
 

 
Dim con As MySqlConnection = New MySqlConnection("Server=localhost;Database=siddhu;Uid=root;Password=1234;")
      Dim message As String = [String].Empty
      Dim cmd As MySqlCommand = New MySqlCommand("login", con)
      con.Open()
      cmd.CommandType = CommandType.StoredProcedure
      cmd.Parameters.Add(New MySqlParameter("user", MySqlDbType.VarChar))
      cmd.Parameters("user").Direction = ParameterDirection.Input
      cmd.Parameters("user").Value = "prasad"
 
      cmd.Parameters.Add(New MySqlParameter("pass", MySqlDbType.VarChar))
      cmd.Parameters("pass").Direction = ParameterDirection.Input
      cmd.Parameters("pass").Value = "530"
 
      cmd.Parameters.Add(New MySqlParameter("@date1", MySqlDbType.Date))
      cmd.Parameters("@date1").Direction = ParameterDirection.Output
      Try
 
      Dim i As Integer
      i = cmd.ExecuteNonQuery()
      If i > 0 Then
          MessageBox.Show(cmd.Parameters("@date1").Value)
      Else
          MessageBox.Show(i)
      End If
      Catch ex As Exception
          MessageBox.Show(ex.ToString())
      End Try
 
      con.Close()
always it give me output as zero
Posted 1-Jan-13 21:20pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I am not sure that executenonquery will return 1, I suggest you check the value of date1 either way and see what it is.
  Permalink  
Comments
kalisiddayya at 2-Jan-13 23:47pm
   
thank u frd
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

to receive out put you have to write a line that will receive output see underlined portion of below code...
cmd.Parameters.Add(New MySqlParameter("@date1", MySqlDbType.Date))
cmd.Parameters("@date1").Direction = ParameterDirection.Output
'execute then...
dim outputdate = cmd.parameters(0).Value 'Index of your Output parameter date1
 
if you are inserting/updating/deleting record then use
cmd.ExecuteNonQuery()
 
if just selecting then
cmd.ExecuteQuery()

 
Happy Coding!
Smile | :)
  Permalink  
Comments
kalisiddayya at 2-Jan-13 23:48pm
   
thank u frd
Aarti Meswania at 2-Jan-13 23:50pm
   
Welcome! :)
Glad to help you! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100