如何在mysql数据库中插入位值? [英] How to insert Bit value in mysql Database?
问题描述
大家好,
你能告诉我如何在MySQL数据库中插入位值.我在下面的C#插入查询中给出.请帮助我解决问题.
Hi to all,
Can you tell me how to insert Bit value in Mysql Database. I am giving below my C# Insert Query. Please Help me to fix problem.
String str1 = "Insert into ExamReview (Student_Name,QuestionPaperName,Question,Option1,Option2,Option3,Option4) values ('" + Session["User_Name"].ToString() + "','" + QuestionPaper + "','" + Question+ "','" + + "','" + + "','" + + "','" + + "')";
在此查询中,我想在选项1中插入位值1,在选项2,选项3和选项4中插入位值0.
感谢所有人.
In this Query, I want to insert Bit value 1 in Option1 And 0 In option2,Option3 and option4.
Thanks to all.
推荐答案
这是我的表
This is my table
+-------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+------+-----+---------+----------------+
| USER_ID | bigint(20) | NO | PRI | NULL | auto_increment |
| USER_ABOUT_YOU | varchar(255) | YES | | NULL | |
| USER_COUNTRY | varchar(255) | YES | | NULL | |
| USER_GENDER | varchar(255) | YES | | NULL | |
| USER_MAILING_LIST | bit(1) | YES | | NULL | |
| USER_NAME | varchar(255) | YES | | NULL | |
| USER_PASSWORD | varchar(255) | YES | | NULL | |
+-------------------+--------------+------+-----+---------+----------------+
这是插入数据的查询
插入到用户中(USER_ID,USER_ABOUT_YOU,USER_COUNTRY,USER_GENDER,USER_MAILING_LIST,USER_NAME,USER_PASSWORD)值(2,``omg'',``India'', ``Female'',b''1'',``test'',``test'');
This is the query to insert data
INSERT INTO `user` (`USER_ID`, `USER_ABOUT_YOU`, `USER_COUNTRY`, `USER_GENDER`, `USER_MAILING_LIST`, `USER_NAME`, `USER_PASSWORD`) VALUES (2, ''omg'', ''India'', ''Female'', b''1'', ''test'', ''test'');
1)有关位字段的信息,请参见MySQL参考:http://dev.mysql.com/doc/refman/5.0/en/bit-field- literals.html [ ^ ]
2)不要使用字符串连接来构建sql语句(您要将应用程序暴露给SQLinjection),请使用参数(sse: ^ ])方法.
1) See MySQL reference about bit fields: http://dev.mysql.com/doc/refman/5.0/en/bit-field-literals.html[^]
2) Don''t use string concatenation for building sql statement (you are exposing your app to SQLinjection), use parameters (sse: AddWithValue[^]) method.
这篇关于如何在mysql数据库中插入位值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!