call a function from a class

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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 OleDbDataAdapter DbStatusWrite(
OleDbConnection connection)]. this is doesn't work.


from dbsample.cs
namespace eSpace
{
class dbSample
{

public string GetDbValue()
{
return something..
}

public static OleDbDataAdapter DbStatusWrite(
OleDbConnection connection)
{
somecode
return somecode
}

}
}


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


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

sm.DbStatusWrite() (the function is not seen from
intellisense )


}

}
}
 
Hi iWrite,

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

dbSample.DbStatusWrite()



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 OleDbDataAdapter DbStatusWrite(
OleDbConnection connection)]. this is doesn't work.


from dbsample.cs
namespace eSpace
{
class dbSample
{
public string GetDbValue()
{
return something..
}
public static OleDbDataAdapter DbStatusWrite(
OleDbConnection connection)
{
somecode
return somecode
}

}
}


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


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

sm.DbStatusWrite() (the function is not seen from
intellisense )


}

}
}
 
Back
Top