DbManager Class

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

Guest

I have a DbManager class that has all my connect stuff like connecting to the
bd and inserting data, but for some reason when I call the insert coammand
for the DbManager class I get A Method 'Network_Inventory.DbManager.Insert()'
referenced without parentheses

Here is my DbManager Class code
public void Insert()
{
OleDbCommand cmdInsert = new OleDbCommand();
cmdInsert.ExecuteNonQuery();
}
Here is my save btn that calls it
private void btnSave_Click(object sender, System.EventArgs e)
{
DbManager manager = new DbManager();
manager.conn();
manager.Insert = "insert into Wired(RouterName) values ('" +
txtRouterName.Text + "')";
}
Can some one help
 
It looks like you're using Insert as a property when it's actually a method,
see inline:

freddy said:
I have a DbManager class that has all my connect stuff like connecting to
the
bd and inserting data, but for some reason when I call the insert coammand
for the DbManager class I get A Method
'Network_Inventory.DbManager.Insert()'
referenced without parentheses

Here is my DbManager Class code
public void Insert()
{
OleDbCommand cmdInsert = new OleDbCommand();
cmdInsert.ExecuteNonQuery();
}
Here is my save btn that calls it
private void btnSave_Click(object sender, System.EventArgs e)
{
DbManager manager = new DbManager();
manager.conn();
manager.Insert = "insert into Wired(RouterName) values ('" +
txtRouterName.Text + "')";

should be:
manager.Insert("insert into Wired(RouterName) values ('" +
txtRouterName.Text + "')");
}
Can some one help

Just a work of warning, using the above code leaves you wide open to SQL
injection attacks. Whenever possible you should use parameters instead of
just concatenating strings.
 
BTW, the code you posted could potentially open you up to SQL Injection
attacks. You might consider using parameterized queries instead.

Thx
 
Back
Top