473,378 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

sql Parameters

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 + "')";
}
How would I change
private void btnSave_Click(object sender, System.EventArgs e)
{
DbManager manager = new DbManager();
manager.conn();
manager.Insert = "insert into Wired(RouterName) values ('" +
txtRouterName.Text + "')";
}
to sql Parameters
Nov 16 '05 #1
2 1471
freddy <fr****@discussions.microsoft.com> wrote:
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
And it's absolutely right - you've used it as if it were a property:
manager.Insert = "insert into Wired(RouterName) values ('" +
txtRouterName.Text + "')";


Note that inserting values directly into SQL is very dangerous - it
opens you up to SQL injection attacks. You should use parameterised
queries instead.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Freddy,

I don't see for what kind of database (I assume something for CE) you are
making this, however I think that this code can work, where I don't
understand the Insert String and assume that you have created the connection
in the constructor from the Class DBManager. The connection close is not
done in this by the way, I don't know how your database act on that.

public void Insert(string ins)
{
OleDbCommand cmdInsert = new OleDbCommand(ins);
cmdInsert.ExecuteNonQuery();
}

private void btnSave_Click(object sender, System.EventArgs e)
{
DbManager manager = new DbManager();
manager.Insert("insert into Wired(RouterName) values ('" +
txtRouterName.Text + "')";
}

Just rougly changed in your message so watch typos or others mistakes.

I hope this helps?

Cor
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tim::.. | last post by:
Can someone tell me a better way or give me a link that shows a better way to create large numbers of SQL parameters... Example... A better way to write this code! <code> Sub...
0
by: Tim::.. | last post by:
Can someone tell me a better way or give me a link that shows a better way to create large numbers of SQL parameters... Example... A better way to write this code! <code> Sub...
14
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To...
2
by: Hexman | last post by:
Hello All, Well I'm stumped once more. Need some help. Writing a simple select and update program using VB.Net 2005 and an Access DB. I'm using parameters in my update statement and when trying...
12
by: pamelafluente | last post by:
Hi guys, In the past I have used several time optional parameters in my function. But Now I am more inclined to think that they are more dangerous than useful, and probably better to be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.