当前位置: 首页>>代码示例>>C#>>正文


C# InfoCommand.ExecuteScalar方法代码示例

本文整理汇总了C#中Srvtools.InfoCommand.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# InfoCommand.ExecuteScalar方法的具体用法?C# InfoCommand.ExecuteScalar怎么用?C# InfoCommand.ExecuteScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Srvtools.InfoCommand的用法示例。


在下文中一共展示了InfoCommand.ExecuteScalar方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetTableNames

        public object GetTableNames(object[] parames)
        {
            ClientType ct = ClientType.ctMsSql;
            IDbConnection nwindConn = AllocateConnection(GetClientInfo(ClientInfoType.LoginDB).ToString(), ref ct, false);
            try
            {
                string strSql = "";
                if (nwindConn is SqlConnection)
                {
                    strSql = "select @@version as version";
                    InfoCommand cmd = new InfoCommand(ClientInfo);
                    cmd.CommandText = strSql;
                    cmd.Connection = nwindConn;
                    Object o = cmd.ExecuteScalar();
                    if (o.ToString().ToLower().IndexOf("microsoft sql server 2005") >= 0)
                    {
                        strSql = @"select (
                                case when b.name != 'dbo' then
                                case when (Charindex(' ',Rtrim(Ltrim(b.name)),0) > 0) then
                                    '[' + b.[name] + ']'
                                else
                                    b.[name]
                                end
                                + '.' +
                                case when (Charindex(' ',Rtrim(Ltrim(a.name)),0) != 0) then
                                    '[' + a.[name] + ']'
                                else
                                    a.[name]
                                end
                            else
                                case when (Charindex(' ',Rtrim(Ltrim(a.name)),0) != 0) then
                                    '[' + a.[name] + ']'
                                else
                                    a.[name]
                                end
                            end
                        )as name from sysobjects a,sys.schemas b where a.uid=b.schema_id and a.xtype in ('u','U','v','V') order by a.[name]";
                    }
                    else
                    {
                        strSql = @"select(
                            case when (Charindex(' ',Rtrim(Ltrim(name)),0) != 0) then
                                '[' + [name] + ']'
                            else
                                [name]
                            end
                            ) as name from sysobjects where xtype in ('u','U','v','V')  order by [name]";
                    }
                }
                else if (nwindConn is OdbcConnection)
                    strSql = "select * from systables where (tabtype = 'T' or tabtype = 'V') and tabid >= 100 order by tabname";
                else if (nwindConn is OracleConnection)
                {
                    return new object[] { 0, GetTableNames(nwindConn.ConnectionString, nwindConn as DbConnection).ToArray() };
                    //strSql = "SELECT * FROM USER_OBJECTS WHERE OBJECT_TYPE = 'TABLE' OR OBJECT_TYPE = 'VIEW'order by OBJECT_NAME";
                }
                else if (nwindConn is OleDbConnection)
                    strSql = "sp_help";
                else if (nwindConn.GetType().Name == "MySqlConnection")
                    strSql = "show tables;";
                else if (nwindConn.GetType().Name == "IfxConnection")
                    strSql = "select * from SYSTABLES where (TABTYPE = 'T' or TABTYPE = 'V') and TABID >= 100 order by TABNAME";

                InfoCommand cmd2 = new InfoCommand(ClientInfo);
                if (nwindConn is OleDbConnection)
                    cmd2.CommandType = CommandType.StoredProcedure;
                cmd2.CommandText = strSql;
                cmd2.Connection = nwindConn;
                IDataReader reader = cmd2.ExecuteReader();
                List<String> tablesList = new List<string>();
                while (reader.Read())
                {
                    if (nwindConn is SqlConnection)
                        tablesList.Add(reader["name"].ToString());
                    else if (nwindConn is OdbcConnection)
                        tablesList.Add(reader["tabname"].ToString());
                    else if (nwindConn is OracleConnection)
                        tablesList.Add(reader["OBJECT_NAME"].ToString());
                    else if (nwindConn is OleDbConnection)
                        tablesList.Add(reader["NAME"].ToString());
                    else if (nwindConn.GetType().Name == "MySqlConnection")
                        tablesList.Add(reader[0].ToString());
                    else if (nwindConn.GetType().Name == "IfxConnection")
                        tablesList.Add(reader["tabname"].ToString());
                }
                reader.Close();
                return new object[] { 0, tablesList.ToArray() };
            }
            finally
            {
                ReleaseConnection(GetClientInfo(ClientInfoType.LoginDB).ToString(), nwindConn, false);
            }
        }
开发者ID:san90279,项目名称:UK_OAS,代码行数:93,代码来源:Component.cs

示例2: SavePersonalSettings

        public object[] SavePersonalSettings(object[] objParam)
        {
            ClientType ct = ClientType.ctMsSql;
            IDbConnection conncetion = AllocateConnection(GetClientInfo(ClientInfoType.LoginDB).ToString(), ref ct, true);
            string formName = (string)objParam[0];
            string compName = (string)objParam[1];
            string userId = (string)objParam[2];
            string remark = (string)objParam[3];
            string propContent = (string)objParam[4];

            string sql = string.Format("SELECT COUNT(*) FROM SYS_PERSONAL WHERE FORMNAME='{0}' AND COMPNAME='{1}' AND USERID='{2}'",
                formName,
                compName,
                userId);
            InfoCommand cmd = new InfoCommand(ClientInfo);
            cmd.Connection = conncetion;
            cmd.CommandText = sql;
            try
            {
                int count = (int)cmd.ExecuteScalar();
                if (count > 0)
                {
                    sql = string.Format("UPDATE SYS_PERSONAL SET REMARK='{0}',PROPCONTENT='{1}',CREATEDATE='{2}' WHERE FORMNAME='{3}' AND COMPNAME='{4}' AND USERID='{5}'",
                        remark,
                        propContent,
                        DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                        formName,
                        compName,
                        userId);
                }
                else
                {
                    sql = string.Format("INSERT INTO SYS_PERSONAL (FORMNAME,COMPNAME,USERID,REMARK,PROPCONTENT,CREATEDATE) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}')",
                        formName,
                        compName,
                        userId,
                        remark,
                        propContent,
                        DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
                }
                cmd.CommandText = sql;
                cmd.ExecuteNonQuery();
                return new object[] { 0 };
            }
            catch (Exception e)
            {
                return new object[] { 1, e.Message };
            }
            finally
            {
                ReleaseConnection(GetClientInfo(ClientInfoType.LoginDB).ToString(), conncetion, true);
            }
        }
开发者ID:san90279,项目名称:UK_OAS,代码行数:53,代码来源:Component.cs

示例3: btnOK_Click

 private void btnOK_Click(object sender, EventArgs e)
 {
     string DBName = this.cmbDB.Text;
     string DBString = this.cmbDB.SelectedValue.ToString();
     string DBType = "";
     string itemType = "";
     foreach (DataRow dr in table.Rows)
     {
         if (dr["DBName"].ToString() == DBName)
         {
             DBType = dr["DBType"].ToString();
             break;
         }
     }
     IDbConnection connection = AllocateConnection(DBType, DBString);
     InfoCommand cmd = new InfoCommand();
     string strSql = "select * from MENUITEMTYPE";
     cmd.CommandText = strSql;
     cmd.Connection = connection;
     connection.Open();
     IDataReader dreader = cmd.ExecuteReader();
     bool bItemTypeExisted = false;
     while (dreader.Read())
     {
         if (dreader["ITEMNAME"].ToString() == this.itemName)
         {
             bItemTypeExisted = true;
             itemType = dreader["ITEMTYPE"].ToString();
         }
     }
     dreader.Close();
     if (!bItemTypeExisted)
     {
         //Solution原本不存在,新建一个Solution
         strSql = "insert into MENUITEMTYPE (ITEMTYPE, ITEMNAME) values ('" + this.itemName + "', '" + this.itemName + "')";
         cmd.CommandText = strSql;
         cmd.Connection = connection;
         cmd.ExecuteNonQuery();
         itemType = this.itemName;
     }
     foreach (string menu in this.menuList)
     {
         strSql = "select count(*) from MENUTABLE where PACKAGE = '" + menu + "' and MODULETYPE = 'S' and ITEMTYPE = '" + itemType + "'";
         cmd.CommandText = strSql;
         cmd.Connection = connection;
         int count = (int)cmd.ExecuteScalar();
         if (count == 0)
         {
             strSql = "insert into MENUTABLE (MENUID, CAPTION, PACKAGE, MODULETYPE, ITEMTYPE) " +
                 "values ('" + menu + "id', '" + menu + "', '" + menu + "', 'S', '" + itemType + "')";
             cmd.CommandText = strSql;
             cmd.Connection = connection;
             cmd.ExecuteNonQuery();
         }
     }
     this.Close();
 }
开发者ID:san90279,项目名称:UK_OAS,代码行数:57,代码来源:frmPkgExportDB.cs


注:本文中的Srvtools.InfoCommand.ExecuteScalar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。