简体   繁体   English

从数据库获取数据

[英]Get the data from Database

I'm using visual web developer C#, I set the storeid to default value of 100 from Sql Server. 我正在使用可视化Web开发人员C#,我从Sql Server将storeid设置为默认值100。 I then set the column storeid to visible false cause I want to automatically insert 100 without showing on my form. 然后,我将列storeid设置为可见的false原因,因为我想自动插入100而不在表单上显示。 But every time I try inserting a new record from my form it only shows null in the database storeid column. 但是每次我尝试从表单插入新记录时,它在数据库storeid列中仅显示null。

This is the storeid datagridview column code: 这是storeid datagridview列代码:

<asp:BoundField DataField="StoreID" HeaderText="Store ID" 
SortExpression="StoreID" ConvertEmptyStringToNull="False" ReadOnly="True" Visible="False">

This is the storeid details view code: 这是storeid详细信息视图代码:

<asp:BoundField DataField="StoreID" HeaderText="Store ID" 
 SortExpression="StoreID" ConvertEmptyStringToNull="False" ReadOnly="Visible="False">

This is my storeid column database: 这是我的storeid列数据库:

ALTER TABLE [dbo].[StaffCCD] ADD  CONSTRAINT [DF_StaffCCD_StoreID]  DEFAULT ((100)) FOR [StoreID]

I suspect what is happening is even though the column is hidden, a value of 'Null' for StoreID is still being passed in the Insert. 我怀疑发生的事情是即使隐藏了列,StoreID的'Null'值仍在插入中传递。 A default constraint will only work when no other value is supplied for the column. 仅当没有其他值供列使用时,默认约束才起作用。

I'd test the default value is correctly configured by running an insert statement (without setting Store ID) in SQL Management Studio and checking that Store ID is in fact defaulting correctly to 100. 我将通过在SQL Management Studio中运行插入语句(不设置商店ID)并检查商店ID实际上是否默认为100来正确配置默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM