How to read values of different database Field Types

Source: Internet
Author: User

 

Define variables:

Private   Const   String SQL _select_body_byid =   " Select * From health_t_layout where layoutid = @ layoutid " ;
Private   Const   String Parm_entity_layoutid =   " @ Layoutid " ;
Private   Const   String Parm_entity_layoutcols =   " @ Layoutcols " ;
Private   Const   String Parm_entity_layoutrows =   " @ Layoutrows " ;
Private   Const   String Parm_entity_widthpercent =   " @ Widthpercent " ;
Private   Const   String Parm_entity_remark =   " @ Remark " ;

 

Obtain object classes

  # Region Obtain the layout Object Class Based on the layout ID.
///   <Summary>
/// Obtain the layout Object Class Based on the layout ID.
///   </Summary>
///   <Param name = "questionid"> Layout ID </Param>
///   <Returns> Layout entity class </Returns>
Public   Static Entitylayout getentitylayoutbyid ( Int Layoutid)
{
Sqlconnection myconn = DB. getcon ();
Try
{
Myconn. open ();

Sqlcommand mycomm =   New Sqlcommand (SQL _select_body_byid, myconn );
Sqlparameter parm_layoutid =   New Sqlparameter (parm_entity_layoutid, sqldbtype. Int, 4 );
Parm_layoutid.value = Layoutid;
Mycomm. Parameters. Add (parm_layoutid );
Sqldatareader SDR = Mycomm. executereader ();
While (SDR. Read ())
{
Entitylayout =   New Entitylayout ();
Entitylayout. layoutcols = (SDR [ " Layoutcols " ] = Dbnull. value) ?   0 : Convert. toint32 (SDR [ " Layoutcols " ]);
Entitylayout. layoutid = (SDR [ " Layoutid " ] = Dbnull. value) ?   0 : Convert. toint32 (SDR [ " Layoutid " ]);
Entitylayout. layoutrows = (SDR [ " Layoutrows " ] = Dbnull. value) ? 0 : Convert. toint32 (SDR [ " Layoutrows " ]);
Entitylayout. widthpercent = (SDR [ " Widthpercent " ] = Dbnull. value) ? 0 : Convert. toint32 (SDR [ " Widthpercent " ]);
Entitylayout. remark = (SDR [ " Remark " ] = Dbnull. value) ?   String . Empty: Convert. tostring (SDR [ " Remark " ]);
Entitylayout. Status = (SDR [ " Status " ] = Dbnull. value) ?   False : Convert. toboolean (Dr [ " Status " ]);
Return Entitylayout;
}
SDR. Close ();
SDR. Dispose ();
}
Catch
{
Return   Null ;
}
Finally
{
DB. Close (myconn );
}
Return   Null ;
}
# Endregion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.