比较数据库和datagridviewtextboxcolumn中的数据类型 [英] comparing data types from database and datagridviewtextboxcolumn

查看:72
本文介绍了比较数据库和datagridviewtextboxcolumn中的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何得出结论,某些值恰好是一种类型.

让我解释一下,我做了datagridview控件(由于数据来自多个表,所以我手动填充了该控件),并在上面有textBoxcolumn.用户应在该列中输入数据,浮点数或字符串.在数据库中,我有一个表-T1-从该列保存数据,即每次用户填充datagridview时,在SAVE按钮上单击,表T1保存所有列.
我的问题是数据库表的类型是float或nvarchar,不是我每次都在datagridview上显示的所有列,但这取决于其他一些事情.因此,我必须先进行验证,然后才能在DB中输入值.但是,在datagridview的textboxcolumn中,我将比较新输入的值是float还是string,并且我不能从0到结尾,但是我必须问的是该特定单元格(我记住了行号,以便可以将值精确地确定DB表中的列,在其他未显示的列中,我放入NULL)是DB表T1列的类型,我不知道该怎么做.使用datagridview.rows [i] .cell [1] .value或其他组合.
我尝试使用GetType,但无法解决问题.

How can I conclude that some value is of exactly one type.

Let explain, I made datagridview control (which I populate manully because data is from several tables) and on  it I have textBoxcolumn. In that column user should entering data, float or string. In database I have one table - T1 -  that saving data from that column ie. every time user populate datagridview, on SAVE button click, table T1 save all column.
My problem is that types of database table are float or nvarchar and not all columns I display every time on datagridview but that depend on some other things. So, I must do validation before entering values in DB. But, in textboxcolumn of datagridview I sholud compare if that new entering value is float or string and I can not go from 0 to end but I must ask is that particular cell (I've remeber rows numbers so I can put values in exactly determined column in DB table, and in others that has not been display I put NULL) is the type of DB table T1 column, and I don't know how to do this.
I've tried with typeof but this do not work with datagridview.rows[i].cell[1].value or other combination.
I.ve tried with GetType and I could not resolve problem.

推荐答案

您必须事先知道Sql Table列的类型,但是如果字段的值为null,则该类型肯定是要更改的对象.

这里是怎么做的:

You must know the types of your Sql Table columns in advance but definitely the type is a subbject to change if the value of the field is null.

Here how it is done:

<身体>
if(rdr.HasRows!= false)
foreach(rdr中的System.Data.Common.DbDataRecord行)
如果if(row [0]!= System.DBNull.Value)
latestDate =(DateTime)行. GetValue(0);
latestDate = DateTime .MinValue;
                if ( rdr.HasRows != false )  
                {  
                    foreach ( System.Data.Common.DbDataRecord row in rdr )  
                    {  
                        if ( row[ 0 ] != System.DBNull.Value )  
                            latestDate = ( DateTime )row.GetValue ( 0 );  
                        else  
                            latestDate = DateTime.MinValue;  
                    }  
                } 


这篇关于比较数据库和datagridviewtextboxcolumn中的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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