call a function from a class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • iWrite

    call a function from a class

    i want some of the functions to be in dbsample.cs and call it from form1.cs,
    and want to know which is the right way to do so. If i create [public string
    SomeFuction()] it works but [public static OleDbDataAdapte r DbStatusWrite(
    OleDbConnection connection)]. this is doesn't work.


    from dbsample.cs
    namespace eSpace
    {
    class dbSample
    {

    public string GetDbValue()
    {
    return something..
    }

    public static OleDbDataAdapte r DbStatusWrite(
    OleDbConnection connection)
    {
    somecode
    return somecode
    }

    }
    }


    from Form1.cs
    namespace eSpace
    {
    public partial class Form1 : Form
    {
    private dbSample sm = new dbSample();


    private void TestButton_Clic k(object sender, EventArgs e)
    {
    this works fine
    sm.GetDbValue() ;

    sm.DbStatusWrit e() (the function is not seen from
    intellisense )


    }

    }
    }
  • Morten Wennevik

    #2
    Re: call a function from a class

    Hi iWrite,

    DbStatusWrite is static so you can't call it from an instance of the class. Use the class name instead

    dbSample.DbStat usWrite()



    On Sun, 29 May 2005 17:52:01 +0200, iWrite <iWrite@discuss ions.microsoft. com> wrote:
    [color=blue]
    > i want some of the functions to be in dbsample.cs and call it from form1.cs,
    > and want to know which is the right way to do so. If i create [public string
    > SomeFuction()] it works but [public static OleDbDataAdapte r DbStatusWrite(
    > OleDbConnection connection)]. this is doesn't work.
    >
    >
    > from dbsample.cs
    > namespace eSpace
    > {
    > class dbSample
    > {
    > public string GetDbValue()
    > {
    > return something..
    > }
    > public static OleDbDataAdapte r DbStatusWrite(
    > OleDbConnection connection)
    > {
    > somecode
    > return somecode
    > }
    >
    > }
    > }
    >
    >
    > from Form1.cs
    > namespace eSpace
    > {
    > public partial class Form1 : Form
    > {
    > private dbSample sm = new dbSample();
    >
    >
    > private void TestButton_Clic k(object sender, EventArgs e)
    > {
    > this works fine
    > sm.GetDbValue() ;
    >
    > sm.DbStatusWrit e() (the function is not seen from
    > intellisense )
    >
    >
    > }
    >
    > }
    > }
    >[/color]



    --
    Happy coding!
    Morten Wennevik [C# MVP]

    Comment

    Working...