如何在SQL中向表中发送C#bool? [英] How can I send a C# bool to a table in SQL?

查看:82
本文介绍了如何在SQL中向表中发送C#bool?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已编写代码来判断是否已处理某些内容。现在我只需要编写一些代码,将我在C#中的代码中的布尔值发送到SQL中的表中。它看起来应该很简单,但我很新,无法理解,谷歌还没有为我做任何事情。



我感谢任何人阅读本文的时间。



I have written code to tell if something has been processed. Now I just need to code something that sends a boolean from my code in C# to my table in SQL. It seems like it should be simple, but I am very new and can't figure it out, and Google hasn't turned anything out for me yet.

I thank anyone for their time reading this.

if (notificationProcessed != null)
             if (notificationProcessed.passed)
//TODO: send Passed to Notification Table using Notification_Insert stored proc?
             _notificationList.RemoveAt(i);





我试图写一下如果通知是通过那么把它放在我的sproc的已处理表中:





and I'm trying to write that if the notification is "passed" then to put that in the "processed" table of my sproc:

SELECT TOP 1000 [NotificationID]
      ,[NotificationMasterID]
      ,[NotificationTypeID]
      ,[NotificationStatusID]
      ,[RecordID]
      ,[ModifyDate]
      ,[ModifyUser]
      ,[Processed]
  FROM [FOO].[dbo].[Notification]

推荐答案

正如其他人所建议的那样,在SQL Server中,您可以使用 BIT 的数据类型[ ^ ]

参见 SQL数据类型映射 [ ^ ]



请注意数据库处理程序内置到.net应该为您处理任何转换。例如,您可以执行以下操作...
As the others have suggested, in SQL Server you can use a datatype of BIT[^]
See also SQL Data Type Mappings[^]

Note that the database handlers built into .net should take care of any conversion for you. For example you can do something like this...
SqlCommand cmd = new SqlCommand("insert into Product (ProductName, Active) values(@prod, @active)", con);
cmd.Parameters.AddWithValue("@prod", "A new product");
cmd.Parameters.AddWithValue("@active", true);
int rowsAffected = cmd.ExecuteNonQuery(); 


试试这些链接 -

配置参数和参数数据类型 [ ^ ]

如何:使用ADO.NET和Visual C#.NET调用参数化存储过程 [ ^ ]

带参数的C#存储过程 [ ^ ]
Try these links -
Configuring Parameters and Parameter Data Types[^]
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET[^]
C# Stored Procedure with Parameter [^]


您必须在表中获取数据域位类型,然后您可以将boolean或bool值存储到数据库。
You have to take datafield bit type in table and then you can store boolean or bool value to database.


这篇关于如何在SQL中向表中发送C#bool?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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