Calling the Function

Posts   
 
    
Steve2106
User
Posts: 6
Joined: 28-Feb-2008
# Posted on: 28-Feb-2008 12:01:21   

Hi Guys,

First post here. Can some one help me with how I call a function? This is part of the code generated by LLBLGen:

Namespace Test2602 Public Class ClientandPhone Inherits DBInteractionBase

Region " Class Member Declarations "

    Private         _phoneNum, _mobileNum, _name, _add1 As SqlString

End Region

    Public Sub New()
        ' // Nothing for now.
    End Sub

    Overrides Public Function Insert() As Boolean
        Dim cmdToExecute As SqlCommand  = New SqlCommand()
        cmdToExecute.CommandText = "dbo.[pr_ClientandPhone_Insert]"
        cmdToExecute.CommandType = CommandType.StoredProcedure

        ' // Use base class' connection object
        cmdToExecute.Connection = _mainConnection

How do I call the Insert() Function above from my code.

I'm using Visual Studio 2005 (VB)

Thanks for your help.

Best Regards,

Steve.

Steve2106
User
Posts: 6
Joined: 28-Feb-2008
# Posted on: 28-Feb-2008 14:13:23   

Hi Guys,

Ok I have managed to call the function. I am now getting an error saying I cannot save a null to the database. Obviously this means I am not passing the data correctly. I am missing the point somewhere because:

Overrides Public Function Insert() As Boolean
        Dim cmdToExecute As SqlCommand  = New SqlCommand()
        cmdToExecute.CommandText = "dbo.[pr_ClientandPhone_Insert]"
        cmdToExecute.CommandType = CommandType.StoredProcedure

        ' // Use base class' connection object
        cmdToExecute.Connection = _mainConnection

Insert() is not passed any variables.

How do I set the variables required by this bit of code in the insert():

cmdToExecute.Parameters.Add(New SqlParameter("@lCliAutoId", SqlDbType.BigInt, 8, ParameterDirection.Input, False, 19, 0, "", DataRowVersion.Proposed, _cliAutoId)) cmdToExecute.Parameters.Add(New SqlParameter("@sPhoneNum", SqlDbType.Char, 15, ParameterDirection.Input, False, 0, 0, "", DataRowVersion.Proposed, _phoneNum)) cmdToExecute.Parameters.Add(New SqlParameter("@sMobileNum", SqlDbType.Char, 15, ParameterDirection.Input, False, 0, 0, "", DataRowVersion.Proposed, _mobileNum)) cmdToExecute.Parameters.Add(new SqlParameter("@lAutoId", SqlDbType.BigInt, 8, ParameterDirection.Output, False, 19, 0, "", DataRowVersion.Proposed, _autoId)) cmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, False, 10, 0, "", DataRowVersion.Proposed, _errorCode))

I'm Lost until someone helps me.

Thanks, I appreciate it. Best Regards,

Steve.

Steve2106 wrote:

Hi Guys,

First post here. Can some one help me with how I call a function? This is part of the code generated by LLBLGen:

Namespace Test2602 Public Class ClientandPhone Inherits DBInteractionBase

Region " Class Member Declarations "

    Private         _phoneNum, _mobileNum, _name, _add1 As SqlString

End Region

    Public Sub New()
        ' // Nothing for now.
    End Sub

    Overrides Public Function Insert() As Boolean
        Dim cmdToExecute As SqlCommand  = New SqlCommand()
        cmdToExecute.CommandText = "dbo.[pr_ClientandPhone_Insert]"
        cmdToExecute.CommandType = CommandType.StoredProcedure

        ' // Use base class' connection object
        cmdToExecute.Connection = _mainConnection

How do I call the Insert() Function above from my code.

I'm using Visual Studio 2005 (VB)

Thanks for your help.

Best Regards,

Steve.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Feb-2008 14:37:43   

Namespace Test2602 Public Class ClientandPhone Inherits DBInteractionBase

Please refresh my memory, is the above class generated by LLBLGen Pro? If so would you please explain what this class represents, as I don't think LLBLGen Pro uses a class called DBInteractionBase.

Which runtime library version of LLBLGen Pro are you using? Please check the following thread to know how to get the correct RTL version number: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7725

Also would you please explain what are you trying to do with calling that function, if you are attempting to access a database Stored Procedure, you may map a call to it using the LLBLGen Pro designer. Please check the following manual's sections: 1- using the designer -> Adding stored procedure calls 2- using the generated code -> SelfServicing/Adapter -> Calling a stored procedure

Steve2106
User
Posts: 6
Joined: 28-Feb-2008
# Posted on: 28-Feb-2008 15:31:52   

Hi There,

It's not the pro version. I am using LLBLGen 1.21

Thanks for your help.

Best Regards,

Steve.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39905
Joined: 17-Aug-2003
# Posted on: 29-Feb-2008 10:03:00   

We don't support the free LLBLGen 1.21 anymore. If you need something, you've to build it in yourself, the sourcecode is available.

Frans Bouma | Lead developer LLBLGen Pro
Steve2106
User
Posts: 6
Joined: 28-Feb-2008
# Posted on: 29-Feb-2008 10:29:02   

Hi Otis,

Well thanks for the help! If you needed to reply, a little help in the right direction would have been very beneficial. Maybe I'm just testing out the product and the support. I know the quality of the support now.

If the source code is available why don't you give a link to it?

Support means Support not brush off.

Best Regards,

Steve.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39905
Joined: 17-Aug-2003
# Posted on: 29-Feb-2008 10:52:08   

Steve2106 wrote:

Hi Otis,

Well thanks for the help! If you needed to reply, a little help in the right direction would have been very beneficial. Maybe I'm just testing out the product and the support. I know the quality of the support now.

Err. sorry?

I wrote LLBLGen 1.x (the free original version) back in 2002, I released the sourcecode as-is as BSD2 licensed code. Here: http://www.sd.nl/software

It's free, open source code with a flexible license. I.o.w.: where exactly am I obligated to help anyone with that old sourcecode? I invested a lot of time writing that code and the documentation, and gave it away for free, and now you're telling me that I'm obligated to help you? Aren't you agreeing that this is abit rude to ask that from me? After all the time I've spend in LLBLGen and its docs which I gave away for free?

This forum is for support on LLBLGen Pro, which is a commercial toolkit, available here: http://www.llblgen.com It's a total different codebase, approach etc. It's a successor of LLBLGen 1.21, but has no code in common with it. If you consider our support quality for LLBLGen Pro, which is top notch, just look around on this forum, now below average because we don't support an old free codebase anymore, I'm sorry, but that's all we can do: we don't support that old codebase anymore.

If the source code is available why don't you give a link to it?

It's available from the same link as where you downloaded LLBLGen 1.21, see above.

Support means Support not brush off.

I think with almost 21000 posts to this support forum alone I know what support means, don't you think? wink

I haven't looked at that code base for years, so I can't help you where to add the call. The generator uses a fixed set of write instructions to write out the code it generates so it's not a template as we use in llblgen pro. One of the reasons LLBLGen Pro was written was that LLBLGen 1.21 was very limited, narrow mindedly focussed on procs and not really extensible.

Frans Bouma | Lead developer LLBLGen Pro
Steve2106
User
Posts: 6
Joined: 28-Feb-2008
# Posted on: 29-Feb-2008 12:22:51   

Hi Otis,

Ok, Sorry if I came across rude. That was not my intention. I just think that with this code some simple web pages, showing how to use the classes would have been helpful. I have been trying for days to call a simple insert but I keep getting an error message 'Can not insert null'. I know this is because I am not passing the value of the text box to the function but I can not work out how to do it. This bit of code is the problem: cmdToExecute.Parameters.Add(New SqlParameter("@sPhoneNum", SqlDbType.Char, 15, ParameterDirection.Input, False, 0, 0, "", DataRowVersion.Proposed, _phoneNum))

How do I pass the phoneNum to the Insert() function?

Best Regards,

Steve.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39905
Joined: 17-Aug-2003
# Posted on: 29-Feb-2008 12:31:18   

Steve2106 wrote:

Hi Otis,

Ok, Sorry if I came across rude. That was not my intention. I just think that with this code some simple web pages, showing how to use the classes would have been helpful.

In the documentation, check the page Examples: 'very simple database'. The tool comes with documentation in the form of html pages.

I have been trying for days to call a simple insert but I keep getting an error message 'Can not insert null'. I know this is because I am not passing the value of the text box to the function but I can not work out how to do it. This bit of code is the problem: cmdToExecute.Parameters.Add(New SqlParameter("@sPhoneNum", SqlDbType.Char, 15, ParameterDirection.Input, False, 0, 0, "", DataRowVersion.Proposed, _phoneNum))

How do I pass the phoneNum to the Insert() function?

That's the code creating parameters for the proc to call. Example of storing a row:

/// <summary>
/// Purpose: creates a new employee record.
/// </summary>
private void CreateNewEmployee()
{
    clsEmployees oEmployees = new clsEmployees();
    
    // load image from file
    FileStream fsBLOBFile = new FileStream(tbxImageFile.txt, FileMode.Open, FileAccess.Read);
    Byte[] bytBLOBData = new Byte[fsBLOBFile.Length]; 
    fsBLOBFile.Read(bytBLOBData, 0, bytBLOBData.Length);
    fsBLOBFile.Close();

    oEmployees.Picture = bytBLOBData;
    oEmployees.StartedOn = dtpEmployeeStartedOn.Value;
    oEmployees.Description = tbxEmployeeDescription.Text;
    oEmployees.FirstName = tbxEmployeeFirstname.Text;
    oEmployees.Initials = tbxEmployeeInitials.Text;
    oEmployees.MiddleName = SqlString.Null;
    oEmployees.LastName = tbxEmployeeLastName.Text;
    oEmployees.SecurityID = int.Parse(tbxSecurityID.Text);

    try
    {
        bool bResult = oEmployees.Insert();
        int iEmployeeID = (int)oEmployees.EmployeeID;
        
        // Do something with the iEmployeeID value
        // ...
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

(from the docs)

Frans Bouma | Lead developer LLBLGen Pro
Steve2106
User
Posts: 6
Joined: 28-Feb-2008
# Posted on: 29-Feb-2008 22:36:31   

Hi Otis,

Thanks for that. It makes it more clearer now.

Best Regards,

Steve.