void RefreshSchema()
        {
            // creates metadata
            if (SelectCommand == null)
            {
                throw new InvalidOperationException("SelectCommand should be valid");
            }
            if (SelectCommand.Connection == null)
            {
                throw new InvalidOperationException("SelectCommand's Connection should be valid");
            }

            CommandBehavior behavior = CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo;

            if (SelectCommand.Connection.State != ConnectionState.Open)
            {
                SelectCommand.Connection.Open();
                behavior |= CommandBehavior.CloseConnection;
            }

            OdbcDataReader reader = SelectCommand.ExecuteReader(behavior);

            _schema = reader.GetSchemaTable();
            reader.Close();

            // force creation of commands
            _insertCommand = null;
            _updateCommand = null;
            _deleteCommand = null;
            _tableName     = String.Empty;
        }
Example #2
0
    protected void Button1_Click1(object sender, EventArgs e)
    {
        int    count   = 0;
        string cmdText = @"SELECT 1 FROM Login 
                               WHERE Username = @uname 
                                 AND Password = @pwd";

        using (SqlConnection cnn = new SqlConnection(conString))
            using (SqlCommand cmd = new SqlCommand(cmdText, cnn))
            {
                cnn.Open();
                cmd.Parameters.Add("@uname", SqlDbType.NVarChar).Value = textBox1.Text;
                cmd.Parameters.Add("@pwd", SqlDbType.NVarChar).Value   = textBox1.Text;
                using (SqlDataReader myReader = SelectCommand.ExecuteReader())
                {
                    while (myReader.Read())
                    {
                        count = count + 1;
                    }
                }
            }
        if (count == 1)
        {
            //open form
        }
        else
        {
        }
    }
        public static bool Login(string usercode, string password, string type)
        {
            MySqlConnection myConn   = new MySqlConnection();
            MySqlDataReader myReader = null;
            bool            isFound  = false;

            try
            {
                myConn = new MySqlConnection(connection);
                MySqlCommand SelectCommand = new MySqlCommand();
                if (type == "student")
                {
                    SelectCommand = new MySqlCommand("Select * from enroldb.student_info where SN='" + usercode + "' And Password ='******';", myConn);
                }
                else if (type == "admin")
                {
                    SelectCommand = new MySqlCommand("Select * from enroldb.user where Username='******' And Password ='******';", myConn);
                }
                myConn.Open();
                myReader = SelectCommand.ExecuteReader();
                int count = 0;
                while (myReader.Read())
                {
                    count = count + 1;
                }
                if (count == 1)
                {
                    isFound = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                myConn.Close();
                myReader.Close();
            }
            return(isFound);
        }
Example #4
0
        public override void Execute()
        {
            // Create the sub-tasks.
            if (UseDataRecordToBuild == null)
            {
                UseDataRecordToBuild = new UseDataRecordToBuild <T>();
            }

            var objectList = new List <T>();

            using (var dataReader = SelectCommand.ExecuteReader())
            {
                while (dataReader.Read())
                {
                    UseDataRecordToBuild.DataRecord = dataReader;
                    UseDataRecordToBuild.Execute();
                    objectList.Add(UseDataRecordToBuild.Object);
                }
            }

            ObjectsFetched = objectList.ToArray();
        }
Example #5
0
        public override void Execute()
        {
            // Create the sub-tasks.
            if (UseDataRecordToBuild == null)
            {
                UseDataRecordToBuild = new UseDataRecordToBuild <T>();
            }

            using (var dataReader = SelectCommand.ExecuteReader())
            {
                // TODO - i don't trust this works in all cases...
                //if (!dataReader.Read())
                //    throw new SingleNotFoundException("No records were found.");

                //if(dataReader.Read())
                //    throw new SingleNotFoundException("More than one record was found.");
                dataReader.Read();
                UseDataRecordToBuild.DataRecord = dataReader;
                UseDataRecordToBuild.Execute();
                ObjectFetched = UseDataRecordToBuild.Object;
            }
        }
        public User GetUserLoginDetail(string userName)
        {
            SelectCommand cmd = new SelectCommand("GetUserLoginDetail");

            cmd["@UserName"] = userName;
            User user = new User();
            using (DBDataReaderWrapper reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {

                    user.Id = reader.Int["UserId"];
                    user.UserName = reader.String["UserName"];
                    user.Password = reader.String["Password"];
                    user.IsActive = reader.Bool["IsActive"];
                    user.MobilePhone = reader.String["MobilePhone"];
                    user.Email = reader.String["EmailId"];
                    user.LastLoginDate = reader.Date["LastLoginDate"];
                    user.RoleList = reader.String["RoleList"].Split(',').Skip(1).Select(r => new Role { RoleName = r });
                }
            }

            return user;
        }
        /// <summary>
        /// Runs the stand-alone SELECT command to retrieve fields that were not present when the item was
        /// created (in either independent or collection-owned mode).
        /// </summary>
        public virtual void RetrieveMissingFields()
        {
            if (DataManager.ProxyMode)
            {
                ProxyRequestAction action = ProxyClient.Request.AddAction(this, MethodInfo.GetCurrentMethod());
                action.OnComplete = delegate()
                {
                    DataTable table = ProxyClient.Result[action].GetData <DataTable>("_table");
                    _table = table;
                    _missingFields.Clear();

                    // When no owner just swap tables,
                    if (_owner == null)
                    {
                        _row = table.Rows[0];
                    }
                    else
                    {
                        _retrievedFieldRow = table.Rows[0];
                    }
                };
            }
            else
            {
                if (SelectCommand == null)
                {
                    throw new InvalidOperationException("There is no defined SELECT command so missing fields cannot be retrieved.");
                }

                // Only do something if there are missing fields to complete
                if (_missingFields.Count > 0 && _selectCmd != null)
                {
                    ConnectionKey key = null;

                    // Gets parameter values
                    foreach (SqlParameter param in SelectCommand.Parameters)
                    {
                        if (param.SourceColumn != null && param.SourceColumn != String.Empty)
                        {
                            // Map to the row or to the backup hash according to state
                            param.Value = _row.RowState == DataRowState.Deleted || _row.RowState == DataRowState.Detached ?
                                          _backupFieldValues[param.SourceColumn] :
                                          _row[param.SourceColumn];
                        }
                        else
                        {
                            param.Value = DBNull.Value;
                        }
                    }

                    try
                    {
                        key = DataManager.Current.OpenConnection(this);
                        SqlDataReader reader = SelectCommand.ExecuteReader();
                        using (reader)
                        {
                            if (!reader.HasRows)
                            {
                                throw new DataItemInconsistencyException("Error retrieving item data - item no longer exists");
                            }
                            else
                            {
                                // Read the first row
                                reader.Read();

                                DataRow rowToUse;

                                // When object is part of the collection, initialize the internal table to hold retrieved fields
                                if (_owner != null && _table == null)
                                {
                                    _table = new DataTable("_table");
                                    OnInitializeTable();
                                    _retrievedFieldRow = _table.NewRow();
                                    _table.Rows.Add(_retrievedFieldRow);

                                    rowToUse = _retrievedFieldRow;
                                }
                                else
                                {
                                    rowToUse = _row;
                                }

                                foreach (string missingField in _missingFields)
                                {
                                    try
                                    {
                                        if ((_row.RowState == DataRowState.Deleted || _row.RowState == DataRowState.Detached) &&
                                            rowToUse == _row)
                                        {
                                            // Update the backup hash when state is inaccessible
                                            _backupFieldValues[missingField] = reader[missingField];
                                        }
                                        else
                                        {
                                            rowToUse[missingField] = reader[missingField];
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        // If a field assigment failed, the select command
                                        throw new DataItemInconsistencyException("Error setting item data - retrieved data does not match item's internal structure", ex);
                                    }
                                }

                                // Done getting the missing fields, so clear them
                                _missingFields.Clear();
                            }
                        }
                    }
                    finally
                    {
                        DataManager.Current.CloseConnection(key);
                    }
                }
                if (ProxyServer.InProgress)
                {
                    ProxyServer.Current.Result[ProxyServer.Current.CurrentAction].AddData("_table", _table);
                }
            }
        }