Delete doesnt seem to work in SQL

S

Stefan

Can someone possibly tell me why my delete statement in sql is not
deleting anything.



Table1:

CurUser | Inventory
John Stalls, Machine
John Stalls, Pinball
John Stalls, Golf
Harry Simpson, Tires
Harry Simpson, Boats

//--------------------------------------------------------------//
String FileName = System.IO.Directory.GetCurrentDirectory() +
"\\test.db";
string ConnectionString = string.Format(@"Data
Source={0};Version=3;New=False", FileName);
SQLiteConnection conn = new SQLiteConnection(ConnectionString);
conn.Open();

SQLiteCommand cmd = conn.CreateCommand();
cmd.CommandText = "DELETE FROM Table1 WHERE CurUser = John Stalls";
cmd.ExecuteNonQuery();
conn.Close();
//--------------------------------------------------------------//

My understanding is that when I execute the command, all the rown with
the user name "John Stalls" should be deleted. But actually nothing
happens when I issue the command.


Thanks

--
 
H

Harlan Messinger

Stefan said:
Can someone possibly tell me why my delete statement in sql is not
deleting anything.



Table1:

CurUser | Inventory
John Stalls, Machine
John Stalls, Pinball
John Stalls, Golf
Harry Simpson, Tires
Harry Simpson, Boats

//--------------------------------------------------------------//
String FileName = System.IO.Directory.GetCurrentDirectory() +
"\\test.db";
string ConnectionString = string.Format(@"Data
Source={0};Version=3;New=False", FileName);
SQLiteConnection conn = new SQLiteConnection(ConnectionString);
conn.Open();

SQLiteCommand cmd = conn.CreateCommand();
cmd.CommandText = "DELETE FROM Table1 WHERE CurUser = John Stalls";
cmd.ExecuteNonQuery();
conn.Close();
//--------------------------------------------------------------//

My understanding is that when I execute the command, all the rown with
the user name "John Stalls" should be deleted. But actually nothing
happens when I issue the command.

You have to delimit literal strings in SQL statements, with single quotes.

"DELETE FROM Table1 WHERE CurUser = 'John Stalls'"
 
S

Stefan

Harlan said:
You have to delimit literal strings in SQL statements, with single
quotes.

"DELETE FROM Table1 WHERE CurUser = 'John Stalls'"

Wow, thaks a lot, it actually works for me now.

I have a quick question, I was looking at some select statements today
that is supposed to return a lot of values at once.

SELECT store_name FROM Store_Information

When you issue a command like that, how do you catch the returned
information so you can use it?


Thanks again.

--
 
H

Harlan Messinger

Stefan said:
Wow, thaks a lot, it actually works for me now.

I have a quick question, I was looking at some select statements today
that is supposed to return a lot of values at once.

SELECT store_name FROM Store_Information

When you issue a command like that, how do you catch the returned
information so you can use it?

You need to learn more about ADO.NET than the little bit you've learned
from the SQLite example because this is basic information. Look up
"recordset".
 
F

Frank Uray

Hi Stefan

The fastest method is this:
System.Data.DataTable local_DataTable = new
System.Data.DataTable("TableName");

System.Data.SqlClient.SqlDataAdapter local_SqlDataAdapter = new
System.Data.SqlClient.SqlDataAdapter("SELECT * FROM XY", local_SqlConnection);

local_DataTable.BeginLoadData();
local_SqlDataAdapter.Fill(local_DataTable);
local_DataTable.EndLoadData();

Regards
Frank
 
S

Stefan

Frank said:
Hi Stefan

The fastest method is this:
System.Data.DataTable local_DataTable = new
System.Data.DataTable("TableName");

System.Data.SqlClient.SqlDataAdapter local_SqlDataAdapter = new
System.Data.SqlClient.SqlDataAdapter("SELECT * FROM XY",
local_SqlConnection);

local_DataTable.BeginLoadData();
local_SqlDataAdapter.Fill(local_DataTable);
local_DataTable.EndLoadData();

Regards
Frank


Appreciate it Frank, it seems that it's always a bother to a lot of
people in here when newbies ask silly questions. I guess everyone
assumes that everyone in the world is a professional programmer. From
my experience, there is only so much you can learn from a book.
Database is not my thing, I don't like working with them and I don't
think I ever will. At the moment i find myself trying to write a small
DB program for myself in C# which I am very new to also.

I noticed that over in the Borland groups the people there are very
willing to help out the new users. The responses are never met with
sarcasm like "go read a book". It's either you answer the question or
you dont. There are lots of beginners out there who do not code for a
living, personally I don't. This is just a hobby thing once every few
years.
 
P

Peter Duniho

Stefan said:
Appreciate it Frank, it seems that it's always a bother to a lot of
people in here when newbies ask silly questions.

That's a ridiculous generalization.
I guess everyone
assumes that everyone in the world is a professional programmer.

As is that.
[...]
I noticed that over in the Borland groups the people there are very
willing to help out the new users. The responses are never met with
sarcasm like "go read a book".

I doubt Harlan was being sarcastic when he suggested reading a book.
It's actually good advice. Frankly, given that this newsgroup has
nothing at all to do with SQL, for you to get any answers to SQL
questions is pretty good if you ask me.

If you would spend a little more time browsing this newsgroup and
following the questions and answers, you will find that in general, new
users are treated with respect and very frequently get answers to
questions that are really just RTFM types of questions. Your
generalizations are inaccurate and insulting.

Even your original question was answered promptly (less than ten
minutes!) and without complaint. But at some point, inexperienced
programmers do need to be told that they would make better use of
_everyone's_ time (their own, and those they are asking questions) if
they would just go look at some reference material first. Some people
will draw that line earlier than others.
It's either you answer the question or
you dont. There are lots of beginners out there who do not code for a
living, personally I don't. This is just a hobby thing once every few
years.

Not wanting to spend your own time on the activity is not a reason to
then expect others to spend _their_ time on your activity. There is, in
general, a lot more tolerance for the occasional RTFM question when the
person asking it appears to at least be making some effort to track down
answers on their own before they ask the question.

Pete
 
S

Stefan

Peter said:
That's a ridiculous generalization.

Yea right!!!

Not wanting to spend your own time on the activity is not a reason to
then expect others to spend their time on your activity. There is,
in general, a lot more tolerance for the occasional RTFM question
when the person asking it appears to at least be making some effort
to track down answers on their own before they ask the question.

I always spend a lot of time searching for the information i need, but
once I cant find the answer I ask the question. Is it not easier to say
2+4 = 4, rather than say go learn basic math.

I am not only referring to me in this group, I have been reading the
same thing about the microsoft groups for years in other groups.
Thats why I never wanted to use any of the microsoft compilers. All I
had ever read was, they are not very helpful in the microsoft groups.
But I wanted to learn c#, I read so many books, and looked at so many
examples, but that will only go so far. If you are teaching yourself,
thats learning the hard way.

Whenever I post a question, I am trying to learn the right way, and the
most efficient way. Is that asking too much???????????

I have seen people post their code and they get ridiculed, becausing
their coding is sloppy. How do they know their coding style is sloppy
if they are told to go read books. Some say as long as the code works,
then thats fine. I don't go for that, I want to learn the correct way.
 
A

Arne Vajhøj

The fastest method is this:
System.Data.DataTable local_DataTable = new
System.Data.DataTable("TableName");

System.Data.SqlClient.SqlDataAdapter local_SqlDataAdapter = new
System.Data.SqlClient.SqlDataAdapter("SELECT * FROM XY", local_SqlConnection);

local_DataTable.BeginLoadData();
local_SqlDataAdapter.Fill(local_DataTable);
local_DataTable.EndLoadData();

I am very skeptical about DataTable being faster than
DataReader.

Arne
 
A

Arne Vajhøj

You need to learn more about ADO.NET than the little bit you've learned
from the SQLite example because this is basic information. Look up
"recordset".

recordset in .NET ??

Arne
 
A

Arne Vajhøj

Appreciate it Frank, it seems that it's always a bother to a lot of
people in here when newbies ask silly questions. I guess everyone
assumes that everyone in the world is a professional programmer. From
my experience, there is only so much you can learn from a book.
Database is not my thing, I don't like working with them and I don't
think I ever will. At the moment i find myself trying to write a small
DB program for myself in C# which I am very new to also.

I noticed that over in the Borland groups the people there are very
willing to help out the new users. The responses are never met with
sarcasm like "go read a book". It's either you answer the question or
you dont. There are lots of beginners out there who do not code for a
living, personally I don't. This is just a hobby thing once every few
years.

Reading books is one of the best ways to learn, so it is not
bad advice.

I am perfectly willing to believe that certain groups may be
more geared towards beginners. Delphi, PHP etc. has a significant
number of hobby programmers. In a .NET group you will mostly find
professionals and students on the way to become professionals.
Of course that makes a difference.

But this group is not that tough on beginners. There are much
worse groups in that regard. comp.lang.c would be an example of such.

Arne
 
H

Harlan Messinger

Harlan said:
Um, sorry, brain fart. DataTable, DataSet are the applicable objects.

But seriously: Microsoft has taken us through Recordset (DAO) ->
Resultset (RDO) -> Recordset (ADO) -> DataTable (ADO.NET). It's really
annoying.
 
H

Harlan Messinger

Stefan said:
Appreciate it Frank, it seems that it's always a bother to a lot of
people in here when newbies ask silly questions. I guess everyone
assumes that everyone in the world is a professional programmer. From
my experience, there is only so much you can learn from a book.
Database is not my thing, I don't like working with them and I don't
think I ever will. At the moment i find myself trying to write a small
DB program for myself in C# which I am very new to also.

I noticed that over in the Borland groups the people there are very
willing to help out the new users. The responses are never met with
sarcasm like "go read a book".

Sarcastic? When I see a question that indicates that a poster doesn't
know the basics of the area in which he's trying to program, he isn't
going to be helped a whole lot by an answer to the question of the
moment. Learning an area of any endeavor one question at a time is not
effective. (Is that how *you* learned to program? Or program C#, or
program ADO.NET?) So I advise the person who asks such a basic question
that he ought to get himself a background. Helpful resources already
exist all over the place, and I tried (though failed, due to mental
hiatus on my part) to give him a starting point. There wasn't a bit of
sarcasm in my response.
 
H

Harlan Messinger

Stefan said:
Yea right!!!



I always spend a lot of time searching for the information i need, but
once I cant find the answer I ask the question. Is it not easier to say
2+4 = 4, rather than say go learn basic math.

It certainly *isn't* easier to write an entire explanation of DataTables
and DataSets and DataAdapters from scratch than to refer a person to
material that already covers it. (By the way, are you really going
around telling people that 2 + 4 = 4? *That* isn't very helpful.)
I am not only referring to me in this group, I have been reading the
same thing about the microsoft groups for years in other groups.
Thats why I never wanted to use any of the microsoft compilers. All I
had ever read was, they are not very helpful in the microsoft groups.
But I wanted to learn c#, I read so many books, and looked at so many
examples, but that will only go so far. If you are teaching yourself,
thats learning the hard way.

Whenever I post a question, I am trying to learn the right way, and the
most efficient way. Is that asking too much???????????

Then why is steering the person to the most efficient way--to learn the
basics from a cohesive source instead of piecemeal--"sarcasm" in your eyes?
I have seen people post their code and they get ridiculed, becausing
their coding is sloppy. How do they know their coding style is sloppy
if they are told to go read books. Some say as long as the code works,
then thats fine. I don't go for that, I want to learn the correct way.

That's a valid but separate issue. Heaven knows there are hundreds of
"teach yourself HTML" courses on-line by people who haven't the faintest
idea about how to write *good* HTML. How to get data out of a database
is a little different in that regard: I don't think there is a whole lot
of variation in the way that ADO.NET basics can be presented.
 
A

Arne Vajhøj

But seriously: Microsoft has taken us through Recordset (DAO) ->
Resultset (RDO) -> Recordset (ADO) -> DataTable (ADO.NET). It's really
annoying.

It is not so unusual to change terminology over the years.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top