SQL查询 [英] SQL query
问题描述
是否有命令对SQL数据库进行查询?
我设法创建一个sql连接变量,并从中获取信息
带有select查询的SqlDataAdapter,并用它填充
数据集。
如果我想进行插入查询,我不能,因为它没有保存在数据库中,当我关闭应用程序时,我无法再访问它了。
这就是我所做的:
SqlConnection cn = new SqlConnection();
SqlDataAdapter da;
cn = table1TableAdapter.Connection;
cn .Open();
da = new SqlDataAdapter(" INSERT INTO Table1(item,title,cost)
VALUES(''milk'',''低脂肪'',''100'')",cn);
da.InsertCommand = da.SelectCommand;
da.Fill(myDBds," Items") ;
cn.Close();
如何查询?
请帮助,
Ofir。
Is there a command to do a query for an SQL database?
I managed to make a sql connection variable, and to take info from it
by making a SqlDataAdapter with select query in it, and filling the
dataset with it.
If I want to do an insert query, I can''t, because it is not saved in
the DB, and when I close the application I can''t access it any more.
This is what I did:
SqlConnection cn = new SqlConnection();
SqlDataAdapter da;
cn = table1TableAdapter.Connection;
cn.Open();
da = new SqlDataAdapter("INSERT INTO Table1(item,title,cost)
VALUES(''milk'',''low fat'',''100'')",cn);
da.InsertCommand = da.SelectCommand;
da.Fill(myDBds, "Items");
cn.Close();
How do I query?
Please help,
Ofir.
推荐答案
6月1日上午8:14,ofiras< ofi ... @ gmail.comwrote:
On Jun 1, 8:14 am, ofiras <ofi...@gmail.comwrote:
是否有命令要做一个SQL数据库的查询?
我设法创建一个sql连接变量,并从中获取信息
通过在其中创建带有select查询的SqlDataAdapter,并填充带它的
数据集。
如果我想进行插入查询,我不能,因为它没有保存在
数据库,当我关闭应用程序时,我再也无法访问它了。
这就是我所做的:
SqlConnection cn = new SqlConnection ();
SqlDataAdapter da;
cn = table1TableAdapter.Connection;
cn.Open();
da = new SqlDataAdapter(" INSERT INTO Table1(item,title,cost)
VALUES(''milk'',''low fat'',''100'') ",cn);
da.InsertCommand = da.SelectCommand;
da.Fill(myDBds," Items");
cn.Clos e();
如何查询?
请帮助,
Ofir。
Is there a command to do a query for an SQL database?
I managed to make a sql connection variable, and to take info from it
by making a SqlDataAdapter with select query in it, and filling the
dataset with it.
If I want to do an insert query, I can''t, because it is not saved in
the DB, and when I close the application I can''t access it any more.
This is what I did:
SqlConnection cn = new SqlConnection();
SqlDataAdapter da;
cn = table1TableAdapter.Connection;
cn.Open();
da = new SqlDataAdapter("INSERT INTO Table1(item,title,cost)
VALUES(''milk'',''low fat'',''100'')",cn);
da.InsertCommand = da.SelectCommand;
da.Fill(myDBds, "Items");
cn.Close();
How do I query?
Please help,
Ofir.
SqlConnection cn = new SqlConnection();
SqlCommand cmd;
cn = table1TableAdapter .Connection;
cn.Open();
cmd = new SqlCommand(" INSERT INTO Table1(item,title,cost)
VALUES(''milk'',''low fat'',''100'')",cn);
cmd.ExecuteNonQuery();
cmd .Dispose();
cn.Close();
SqlConnection cn = new SqlConnection();
SqlCommand cmd;
cn = table1TableAdapter.Connection;
cn.Open();
cmd = new SqlCommand("INSERT INTO Table1(item,title,cost)
VALUES(''milk'',''low fat'',''100'')",cn);
cmd.ExecuteNonQuery();
cmd.Dispose();
cn.Close();
6月1日下午1点14分,ofiras< ofi ... @ gmail.comwrote:
On Jun 1, 1:14 pm, ofiras <ofi...@gmail.comwrote:
是否有命令对SQL数据库进行查询?
我设法制作一个sql连接变量,并从中获取信息
通过在其中添加带有select查询的SqlDataAdapter,并用它填充
数据集。
如果我想进行插入查询,我不能,因为它没有保存在数据库中,而当我关闭应用程序时,我再也无法访问它了。
Is there a command to do a query for an SQL database?
I managed to make a sql connection variable, and to take info from it
by making a SqlDataAdapter with select query in it, and filling the
dataset with it.
If I want to do an insert query, I can''t, because it is not saved in
the DB, and when I close the application I can''t access it any more.
另一个回复解释了如何做,但重要的是
注意插入*不是* a查询 - 它正在添加数据,而不是
阅读它。
Jon
The other reply explained how to do it, but the important thing to
note is that an insertion *isn''t* a query - it''s adding data, not
reading it.
Jon
6月1日下午2:29,z ... @ construction-imaging.com写道:
On Jun 1, 2:29 pm, z...@construction-imaging.com wrote:
6月1日上午8:14,ofiras < ofi ... @ gmail.comwrote:
On Jun 1, 8:14 am, ofiras <ofi...@gmail.comwrote:
是否有命令对SQL数据库进行查询?
我管理创建一个sql连接变量,并从中获取信息
,在其中创建带有select查询的SqlDataAdapter,并用它填充
数据集。
如果我想进行插入查询,我不能,因为它没有保存在数据库中的
中,当我关闭应用程序时,我无法访问它更多。
这就是我所做的:
Is there a command to do a query for an SQL database?
I managed to make a sql connection variable, and to take info from it
by making a SqlDataAdapter with select query in it, and filling the
dataset with it.
If I want to do an insert query, I can''t, because it is not saved in
the DB, and when I close the application I can''t access it any more.
This is what I did:
SqlConnec cn = new SqlConnection();
SqlDataAdapter da;
SqlConnection cn = new SqlConnection();
SqlDataAdapter da;
cn = table1TableAdapter.Connection;
cn.Open();
da = new SqlDataAdapter(" INSERT INTO Table1(item,title,cost)
VALUES(''milk'',''low fat'',''100'')",cn);
da.InsertCommand = da.SelectCommand;
da.Fill(myDBds," Items");
cn.Close();
cn = table1TableAdapter.Connection;
cn.Open();
da = new SqlDataAdapter("INSERT INTO Table1(item,title,cost)
VALUES(''milk'',''low fat'',''100'')",cn);
da.InsertCommand = da.SelectCommand;
da.Fill(myDBds, "Items");
cn.Close();
如何查询?
请帮助,
Ofir。
How do I query?
Please help,
Ofir.
SqlConnection cn = new SqlConnection();
SqlCommand cmd;
cn = table1TableAdapter .Connection;
cn.Open();
cmd = new SqlCommand(" INSERT INTO Table1(item,title,cost)
VALUES(''milk'',''low fat'',''100'')",cn);
cmd.ExecuteNonQuery();
cmd .Dispose();
cn.Close();
SqlConnection cn = new SqlConnection();
SqlCommand cmd;
cn = table1TableAdapter.Connection;
cn.Open();
cmd = new SqlCommand("INSERT INTO Table1(item,title,cost)
VALUES(''milk'',''low fat'',''100'')",cn);
cmd.ExecuteNonQuery();
cmd.Dispose();
cn.Close();
但是,如果我关闭应用程序,仍然没有牛奶。项目
了。
为什么DB没有更改?
请帮助,
Ofir。
Thenks, but still if I close the aplication, There is no "milk" item
any more.
Why the DB is not changed?
Please help,
Ofir.
这篇关于SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!