伙计们我的数据库遇到了问题 [英] Guys am facing a issue with my database

查看:69
本文介绍了伙计们我的数据库遇到了问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys现在我正面临一个问题,现在我无法解决它bcz我已经尝试了很多方法来解决这个问题,但我失败了所以现在我想得到你的帮助所以请给我更好的答案这个问题

这个问题是当我从数据库中删除单个coloumn值时删除所有coloumn值。请给我解决方法如何删除ms访问中的单列值



  if (textBox63.Text ==  < span class =code-string>)
{
MessageBox.Show( 抱歉!数据空了!请再试一次 报告, MessageBoxButtons.OK,MessageBoxIcon.Error);
return ;
}
else
{
DialogResult dialogResult = form.ShowDialog();
if (textBox.Text == 黑翡翠
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = 从总计中删除[报告] ;
command.ExecuteNonQuery();
connection.Close();
}

else
{

}

< br $> b $ b

谢谢

问候

M.Sajid.Lakha



我尝试过:



if(textBox63.Text ==)

{

MessageBox.Show(抱歉!数据空了!请再试一次,报告,MessageBoxButtons.OK,MessageBoxIcon.Error);

return;

}

其他

{

DialogResult dialogResult = form.ShowDialog();

if(textBox.Text ==Black Emerald)

{

connection.Open();

OleDbCommand command = new OleDbCommand() ;

command.Connection = connection;

command.CommandText =从总计中删除[报告];

command.ExecuteNonQuery();

connection.Close();

}



其他

{



}

解决方案

根据数据库的原则,删除行而不是列。

如果列中需要0,则需要在该列中存储0,这是一个更新。



猜猜SQL的一些研究是有序的。



[更新]

Quote:

我不想删除此列我只想删除此列的所有值您无法删除这些值,你想在每一栏中为每一行添加/存储一个新值!

使用正确的措辞,你会在Google上找到更多帮助。


除了别人所说的,如果你需要的话o从数据库中删除一条记录,你必须传递一些东西进行检查; 首选主键。您使用的代码必须更改为:

   -   确认您要删除报告为空的记录。  
DELETE FROM 总计 WHERE [报告] IS NULL



Dave给你一个想法,SQL希望你告诉要删除哪些记录。否则,它将简单地删除整个记录列表。如果您想以某种方式删除该列,则可以改为更改表并删除列(如果这是预期的)。该命令将是这样的,

  ALTER   TABLE  DROP   COLUMN  [报告] 



这将删除该列。



编辑



既然你想要删除该列中的数据,而不是做任何我建议 UPDATE - 字段。您可以在SQL中这样做,

 更新总计 SET  [Report] =  NULL  



这将更新(整个 - 这是你想要的吗?)表并将其设置为NULL。如果要将一两个记录设置为NULL,则尝试在那里传递WHERE子句。


使用ALTER TABLE来删除列。



ALTER TABLE(Transact-SQL) [ ^ ]



请注意,您确实不需要删除该列。您的代码在不需要时忽略该列会更简单。


Hello Guys Nowadays am facing a issue and now am unable to resolve it bcz i have tried many ways to solve this problem but i was failed so now i want to get your help so please give me the better answer of this issue
This issue is when i delete single coloumn value from database it's delete all coloumn values.please give me the solution how i can delete single column value in ms accesss

if (textBox63.Text == "")
            {
                MessageBox.Show("Sorry! Data was Empty!Please Try Again","Report",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }
            else
            {
                DialogResult dialogResult = form.ShowDialog();
                if (textBox.Text == "Black Emerald")
                {
                    connection.Open();
                    OleDbCommand command = new OleDbCommand();
                    command.Connection = connection;
                    command.CommandText = "Delete [Report] from Total";
                    command.ExecuteNonQuery();
                    connection.Close();
                }

                else
                {

                }



Thanks
Regards
M.Sajid.Lakha

What I have tried:

if (textBox63.Text == "")
{
MessageBox.Show("Sorry! Data was Empty!Please Try Again","Report",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
else
{
DialogResult dialogResult = form.ShowDialog();
if (textBox.Text == "Black Emerald")
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "Delete [Report] from Total";
command.ExecuteNonQuery();
connection.Close();
}

else
{

}

解决方案

By principle in databases, you delete rows, not columns.
If you want 0 in a column, you need to store 0 in that column, it is an update.

Guess some study of SQL is in order.

[Update]

Quote:

i dont want to delete this column i just wanna delete all values of this column

You can't delete the values, you want to put/store a new value in this column for every row !
Use the right wording and you will find much more help on Google.


Apart from what others have said, in case when you are required to delete one record from the database you have to pass something to check against; a primary key is prefered. The code that you are using must be changed to:

-- Assyming you wanted to delete the records where report is null. 
DELETE FROM Total WHERE [Report] IS NULL


Dave gave you an idea of this, SQL expects you to tell what records to delete. Otherwise, it will simply delete the entire list of records. If, somehow you wanted to delete the column, you can instead alter the table and remove the column (if that is what is intended). That command would be like this,

ALTER TABLE Total DROP COLUMN [Report]


This will remove that column.

Edit

Since you wanted to remove the data in that column, instead of doing anything I would recommend UPDATE-ing the fields. You can do so in SQL, like this,

UPDATE Total SET [Report] = NULL


This will update the (entire — is this what you want?) table and set it to NULL. If you want to set a record or two to NULL, then try passing a WHERE clause there.


Use ALTER TABLE to DROP the column.

ALTER TABLE (Transact-SQL)[^]

Note that you don't really need to remove the column. It would be simpler for your code to ignore the column when it isn't needed.


这篇关于伙计们我的数据库遇到了问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆